Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON version #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ code/*.TSP
code/*.TUP
code/lexicon_nonunique.txt
code/tischendorfmorph.OSIS.xml
code/tischlexicon_nonunique.txt
code/tischlexicon_nonunique.txt
.DS_Store
80 changes: 71 additions & 9 deletions code/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def parse_lines_linear(self, lines):
for line in lines:
line = line.replace("\r", "").replace("\n", "")
myarr = line.split(" ")
[mybook, mychapterverse, mybreak_kind, mysurface, myqere, mytag, mystrongs] = myarr[0:7]
[mybook, mychapterverse, mybreak_kind, mysurface, myqere, mytag, mystrongs] = myarr[0:7]
strongslemma = ""
ANLEXlemma = ""
[strongslemma, ANLEXlemma] = " ".join(myarr[7:]).split(" ! ")
Expand Down Expand Up @@ -312,12 +312,12 @@ def process_linear_word(self, mybreak_kind, mysurface, myqere, mytag, mystrongs,
w.ANLEXlemma = ANLEXlemma
self.verses[-1].words.append(w)
self.verses[-1].last_monad = self.end_monad


def open_file(self):
f = open(self.filename, "r")
return f

def parse_lines(self, lines, read_what):
verse_lines = []
for ln in lines:
Expand Down Expand Up @@ -418,7 +418,7 @@ def parse_sentences(self):
if ending_monad != self.end_monad:
self.sentences.append(Sentence(ending_monad+1))

# End the last sentence if the last word of the book
# End the last sentence if the last word of the book
# did not have an end-of-sentence punctuation
if self.sentences[-1].ending_monad != self.end_monad:
self.sentences[-1].set_ending_monad(self.end_monad)
Expand All @@ -442,7 +442,7 @@ def parse_clauses(self):
self.clauses.append(Clause(ending_monad+1))
bHasSeenVerb = False

# End the last clause if the last word of the book
# End the last clause if the last word of the book
# did not have an end-of-clause punctuation
if self.clauses[-1].ending_monad != self.end_monad:
self.clauses[-1].set_ending_monad(self.end_monad)
Expand Down Expand Up @@ -530,7 +530,7 @@ def writeOSIS(self, f):
w = words[index][0]
chapter = words[index][1]
verse = words[index][2]

if w.break_kind == "C":
running_chapter += 1
osisIDChapter = "%s.%s" % (self.OSISBook, running_chapter)
Expand All @@ -549,7 +549,7 @@ def writeOSIS(self, f):

if prev_chapter != chapter:
prev_chapter = chapter

if index == 0:
osisIDVerse = "%s.%s.%s" % (self.OSISBook, chapter, verse)

Expand All @@ -564,6 +564,68 @@ def writeOSIS(self, f):
f.write("""</p>
</chapter></div>""")

def convertNamesToOsisStandard(self, name):
name = name.replace('1 Corinthians','I Corinthians')
name = name.replace('2 Corinthians','II Corinthians')
name = name.replace('1 Thessalonians','I Thessalonians')
name = name.replace('2 Thessalonians','II Thessalonians')
name = name.replace('1 Timothy','I Timothy')
name = name.replace('2 Timothy','II Timothy')
name = name.replace('1 Peter','I Peter')
name = name.replace('2 Peter','II Peter')
name = name.replace('1 John','I John')
name = name.replace('2 John','II John')
name = name.replace('3 John','III John')
name = name.replace('Revelation','Revelation of John')
return name

def writeJSON(self, f):
if self.LongEnglishBook != 'Matthew':
f.write( """,\n""" )
f.write(""""%s": [""" % (self.convertNamesToOsisStandard(self.LongEnglishBook)))

running_chapter = 0

prev_chapter = 0
prev_verse = 0

for v in self.verses:
words = []
for w in v.words:
words.append((w, v.chapter, v.verse))

if v.verse > prev_verse + 1:
f.write(""",\n[]""")

for index in xrange(0, len(words)):
w = words[index][0]
chapter = v.chapter
verse = v.verse

if prev_chapter != chapter:
if prev_chapter != 0:
f.write("""],\n""")
prev_chapter = chapter
f.write("""[""")

if index == 0:
if verse != 1:
f.write(""",\n""")
f.write("""[""")

f.write("""["%s","G%s","%s"]""" % (w.beta2utf8(w.qere), w.Strongs1, w.parsing) )
#f.write("""["%s","G%s","%s"]""" % (w.beta2utf8(w.remove_accents()), w.Strongs1, w.parsing))

if index != len(words)-1:
f.write(""",""")

if index == len(words)-1:
f.write("""]""")

prev_verse = v.verse

f.write("""] ]""")

def writeSFM(self, f, cur_monad):
for v in self.verses:
cur_monad = v.writeSFM(f, cur_monad)
Expand Down Expand Up @@ -595,7 +657,7 @@ def addNonParsedTischWords(self, lexicon, manualanalyses):
for tischverse in self.verses:
verse_copy = self.getVerseCopy(tischverse)
tischverse.addNonParseTischWords(verse_copy, lexicon, manualanalyses)


def addToLexicon(self, lexicon):
for whverse in self.verses:
Expand Down Expand Up @@ -655,7 +717,7 @@ def write_MORPH_style(self, filename, encodingStyle):
def write_subset_MORPH_style(self, f, word_predicate, manualanalyses, encodingStyle):
for whverse in self.verses:
whverse.write_subset_MORPH_style(f, self.getVerseCopy(whverse), word_predicate, manualanalyses, encodingStyle)

def write_StrippedLinear(self, filename):
self.addVersesToVerseDict()
f = open(filename, "w")
Expand Down
8 changes: 8 additions & 0 deletions code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ def read_TSP_writeOSIS():
rd.write_OSIS("tischendorfmorph.OSIS.xml")
return rd

def read_TSP_writeJSON():
rd = read_TSP()
rd.applyLemma(kind.kANLEX)
rd.parse_sentences_and_clauses()
rd.write_JSON("tischendorfmorph.OSIS.json")
return rd

def read_TSP_writeSFM():
rd = read_TSP()
rd.applyLemma(kind.kANLEX)
Expand Down Expand Up @@ -252,3 +259,4 @@ def parseTischendorfBETA():
read_TSP_writeTUP()
#read_TSP_writeMQL()
read_TSP_writeOSIS()
read_TSP_writeJSON()
10 changes: 10 additions & 0 deletions code/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ def write_OSIS(self, osisfilename):
fout.write("""</div></osisText></osis>""")
fout.close()

def write_JSON(self, osisfilename):
fout = open(osisfilename, "w")
fout.write("""{"version": "TISCH", "versionName": "Tischendorf", "meta": {"description": "Tischendorf's 8th Greek New Testament", "source": "https://github.com/morphgnt/tischendorf", "encoding": null, "language": "gk", "license": "Public Domain. Copy freely", "copyright": null}, "books":{""")

for index in range(0,27):
self.books[index].writeJSON(fout)

fout.write("""} }""")
fout.close()


def applyLemma(self, lemmaType):
if lemmaType == kStrongs:
Expand Down
Loading