Skip to content
Permalink
Browse files

Record history of words through language changes

Keeps track of how words were passed through different languages over time.
The names of each language are recorded alongside their nation indices to
avoid having to reify each intermediate language when displaying, which has
the sort of weird side effect that those are the names of the languages at the
time of the borrowing, rather than their present/current names.
  • Loading branch information...
tps12 committed Jan 30, 2018
1 parent 3012bb0 commit 1106594c4f2e3b5162a0eda9f27935e37d0b08ae
Showing with 62 additions and 4 deletions.
  1. +24 −1 historypresenter.py
  2. +23 −1 language/dictionary.py
  3. +15 −2 language/lazy.py
@@ -19,6 +19,11 @@
def capitalize(s):
return s[0].upper() + s[1:]

def conjoin(items):
if len(items) == 1:
return items[0]
return '{} and {}'.format(', '.join(items[:-1]), items[-1])

class HistoryPresenter(object):
def __init__(self, view, uistack, listitemclass):
self._view = view
@@ -146,7 +151,25 @@ def selecttile(self, tile):
text = '{} (/{}/): {}'.format(capitalize(name) if kind is 'nation' else name,
language.output.pronounce(word),
'nation' if kind == 'nation' else self._model.resource(kind, index).name)
wordlist.addChild(self._listitemclass([text]))
entry = self._listitemclass([text])
wordorigin = lang.origin(word)
if wordorigin is not None:
ultimate = wordorigin.ultimate()
ultimateword = language.output.write(ultimate.word)
if ultimate.language[0] != selected:
origin = 'From {}'.format(capitalize(language.output.write(ultimate.language[1])))
if ultimateword != name:
origin += ' "{}"'.format(capitalize(ultimateword) if kind == 'nation' else ultimateword)
via = wordorigin.pedigree()[1:-1]
if via:
origin += ' via {}'.format(conjoin([capitalize(language.output.write(l[1])) for l in via]))
elif ultimateword != name:
origin = 'From "{}"'.format(capitalize(ultimateword) if kind == 'nation' else ultimateword)
else:
origin = None
if origin is not None:
entry.addChild(self._listitemclass([origin]))
wordlist.addChild(entry)
self._view.details.addTopLevelItem(wordlist)

def rotate(self, value):
@@ -1,16 +1,35 @@
class Origin(object):
def __init__(self, word, language, origin=None):
self.word = word
self.language = language
self.origin = origin

def ultimate(self):
return self if self.origin is None else self.origin.ultimate()

def pedigree(self):
if self.origin is None:
return [self.language]
pedigree = self.origin.pedigree()
if self.language[0] == pedigree[0][0]:
return pedigree
return [self.language] + pedigree

class Dictionary(object):
def __init__(self):
self._worddefs = {}
self._defwords = {}
self._origins = {}

def add(self, word, kind, index):
def add(self, word, kind, index, origin):
if self.defines(word):
raise ValueError("Can't duplicate word")
if self.describes(kind, index):
raise ValueError("Can't duplicate definition")
defn = (kind, index)
self._worddefs[word] = defn
self._defwords[defn] = word
self._origins[word] = origin

def rename(self, old, new):
self.add(new, *self.popword(old))
@@ -42,3 +61,6 @@ def lexicon(self):

def defs(self):
return self._defwords.keys()

def origin(self, word):
return self._origins[word]
@@ -27,6 +27,7 @@ def reify(langs, index, ticks, borrowsubset, timing, indent):
(conceptlist, soundchanges, neologisms, loans) = (
langs[index]._concepts, langs[index]._changes, langs[index]._neologisms, langs[index]._loans)
concept_words = {}
origins = {}
existing = set()
for t in range(ticks):
timing.start('{}applying sound changes'.format(indent))
@@ -59,7 +60,9 @@ def reify(langs, index, ticks, borrowsubset, timing, indent):
for i in range(len(concept_indices)):
(concept, coined) = (conceptlist[concept_indices[i]], words[i])
concept_words[concept] = coined
origins[concept] = language.dictionary.Origin(coined, None)
existing.add(coined)

if t in loans:
timing.start('{}borrowing words'.format(indent))
if stats is None:
@@ -70,15 +73,25 @@ def reify(langs, index, ticks, borrowsubset, timing, indent):
continue
timing.start('{}reifying language {}'.format(indent, src))
src_dict = reify(langs, src, t+1, concepts, timing, indent + ' ')
src_name = src_dict.describe('nation', src)
for concept in concepts:
borrowed = borrow(src_dict.describe(*concept), stats, existing)
original = src_dict.describe(*concept)
borrowed = borrow(original, stats, existing)
concept_words[concept] = borrowed
existing.add(borrowed)
origins[concept] = language.dictionary.Origin(original, (src, src_name), src_dict.origin(original))

timing.start('{}setting origins'.format(indent))
lang_name = concept_words[('nation', index)]
for origin in origins.values():
if origin.language is None:
origin.language = (index, lang_name)

timing.start('{}building dictionary'.format(indent))
dictionary = language.dictionary.Dictionary()
for ((kind, index), word) in concept_words.items():
dictionary.add(word, kind, index)
origin = origins[(kind, index)] if (kind, index) in origins else None
dictionary.add(word, kind, index, origin)
return dictionary

class History(object):

0 comments on commit 1106594

Please sign in to comment.
You can’t perform that action at this time.