Skip to content

Commit

Permalink
Move source code into subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
pamolloy committed Nov 23, 2012
1 parent d3ca46e commit d636765
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
2 changes: 0 additions & 2 deletions analysis/analyze.py → genutiv/analysis/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def list_patterns(gender):
print pattern[1:] + '-'
else: pass



def results():
"""Create a dictionary containing results of accuracy test."""

Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions genutiv.py → genutiv/genutiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from reference.wiktionary import Wiktionary

if __name__ == '__main__':
container = set()
wiki = Wiktionary()
wiki.populate()

16 changes: 15 additions & 1 deletion noun.py → genutiv/noun.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ class Noun(object):
def __init__(self, noun):
self.noun = noun
self.created = datetime.now()
self.updated = self.created #TODO Does this assign value?
self.modified = self.created #TODO Does this assign value?
self.gender = ''
self.sourceName = ''
self.sourceAddr = ''

def updateTime(self):
self.updated = datetime.now()

def setGender(self, gender):
self.gender = gender
self.updateTime

def setSourceName(self, name):
self.sourceName = name
self.updateTime

def setSourceAddr(self, address):
self.sourceAddr = address
self.updateTime

class WikiNoun(Noun):
"""A German noun generated by the German Wiktionary"""
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 12 additions & 2 deletions reference/reference.py → genutiv/reference/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@

from datetime import datetime
import wikitools
import pickle

class Reference(object):
"""A reference for the source of the noun and its assigned gender"""

def __init__(self, title, url):
def __init__(self, title, url, filename):
self.title = title
self.url = url
self.created = datetime.now()
self.filename = filename
self.container = set()
self.site = wikitools.wiki.Wiki(self.url)

# Open set of Noun objects
try:
with open(self.filename, 'rb') as store:
self.container = pickle.load(store)
except IOError as e:
print 'File not found'

def addNoun(self, noun):
"""Add a Noun to the container"""

self.container.add(noun)
with open(self.filename, 'wb') as store:
pickle.dump(noun, store, pickle.HIGHEST_PROTOCOL)

def removeNoun(self, noun):
"""Remove a Noun from the container"""
Expand Down
9 changes: 5 additions & 4 deletions reference/wiktionary.py → genutiv/reference/wiktionary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
#
# wiktionary.py
#
Expand Down Expand Up @@ -31,8 +29,8 @@ class Wiktionary(Reference):

def __init__(self):
Reference.__init__(self, 'German Wiktionary',
'http://de.wiktionary.org/w/api.php')

'http://de.wiktionary.org/w/api.php', 'wiktionary.pickle')
# Open dictionary of noun categories
with open('reference/kategorien.json', 'r') as store:
self.category_dict = json.load(store)
Expand All @@ -41,10 +39,13 @@ def populate(self):
"""Create Noun objects from source and store them"""

noun_set = self.lookup_nouns()

for word in noun_set:
noun = Noun(word)
gender = self.lookup_gender(word)
noun.setGender(gender)
noun.setSourceName(self.title)
noun.setSourceAddr(self.url)
self.addNoun(noun)

def lookup_nouns(self):
Expand Down

0 comments on commit d636765

Please sign in to comment.