-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_morphology_grc.sc
120 lines (97 loc) · 2.98 KB
/
update_morphology_grc.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import scala.io.Source
import java.io._
import java.util.Calendar
import scala.collection.mutable.LinkedHashMap
import edu.holycross.shot.scm._
import edu.holycross.shot.cite._
import edu.holycross.shot.ohco2._
import edu.holycross.shot.greek._
import scala.io.StdIn.readLine
import scala.collection.mutable._
import edu.furman.classics.fumorph._
:load morphConfig_grc.sc
val filePath:String = ""
val splitters:String = """[\[\])(·⸁.,·:…;; "?·!–—⸂⸃]"""
def loadLibrary(fp:String):CiteLibrary = {
val library = CiteLibrary(Source.fromFile(fp).getLines.mkString("\n"),"#",",")
library
}
def loadFile(fp:String):Vector[String] = {
Source.fromFile(fp).getLines.toVector
}
def saveString(s:String, fileName:String):Unit = {
val pw = new PrintWriter(new File(filePath + fileName))
pw.append(s)
pw.append("\n")
pw.close
}
def showMe(v:Any):Unit = {
v match {
case _:Iterable[Any] => println(s"""----\n${v.asInstanceOf[Iterable[Any]].mkString("\n")}\n----""")
case _:Vector[Any] => println(s"""----\n${v.asInstanceOf[Vector[Any]].mkString("\n")}\n----""")
case _ => println(s"-----\n${v}\n----")
}
}
/* Variables Below */
val greekLexIndex = loadFile("lexica/new_greek_index.txt").filter(_.split("#").size == 3)
//val gmlib = loadLibrary(greekMorphLibFile)
//val gtlib = loadLibrary("cex/candaules.cex)
//lazy val gmorph:FuMorph = FuMorph(Some(gmlib), gtlib, Greek, greekLexIndex)
val latinLexIndex = loadFile("lexica/new_latin_index.txt").filter(_.split("#").size == 3)
//val lmlib = loadLibrary(greekMorphLibFile)
//val ltlib = loadLibrary("cex/candaules.cex")
//lazy val lmorph:FuMorph = FuMorph(Some(lmlib), ltlib, Latin, latinLexIndex)
//Load and update
var morphLib:Option[FuMorph] = None
var morphLang:MorphLanguage = lang
// Save backup of current morphology
def backup(lib:Option[FuMorph], fileName:String = outputFile):Unit = {
lib match {
case Some(l) => {
val oldMorphology:String = l.backupCex
saveString(oldMorphology, fileName + ".bak" )
}
case None => {
println("No library loaded.")
}
}
}
//Save new morphology
def update(lib:Option[FuMorph], fileName:String = outputFile):Unit = {
lib match {
case Some(l) => {
val newMorphology:String = l.updateCex
saveString(newMorphology, fileName )
}
case None => {
println("No library loaded.")
}
}
}
def loadMorph(libLang:MorphLanguage = morphLang, textLibFile:String = textLibrary) = {
val textLib:CiteLibrary = loadLibrary(textLibFile)
morphLang match {
case Greek => {
val gmlib = loadLibrary(outputFile)
val gmorph:FuMorph = FuMorph(Some(gmlib), textLib, morphLang)
morphLib = Some(gmorph)
}
case _ => {
val lmlib = loadLibrary(outputFile)
val lmorph:FuMorph = FuMorph(Some(lmlib), textLib, morphLang)
morphLib = Some(lmorph)
}
}
}
def updateMorphology:Unit = {
loadMorph()
update(morphLib)
}
def help:Unit = {
println("""---------------------
Build on an existing morphology:
[ edit file morphConfig_grc.sc ]
scala> updateMorphology
---------------------""")
}
help