diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3594473 --- /dev/null +++ b/.gitignore @@ -0,0 +1,222 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml +*.publishproj + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[cod] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +# PyCharm +.idea/ +__pycache__ +*.pyc +*.pyo \ No newline at end of file diff --git a/db_input_parser/__init__.py b/db_input_parser/__init__.py deleted file mode 100644 index 264e423..0000000 --- a/db_input_parser/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -__author__ = 'Matthew' - - -from db_input_parser.add_database_types import create_type_contents -from db_input_parser.parse_dictionary import parse_dict_file -from db_input_parser.parse_inflections import parse_inflect_file - - -def parse_all_inputs(words_folder, commit_changes): - """Creates the database and parses all the inputs""" - - create_type_contents() - - parse_inflect_file(inflect_file=words_folder + 'INFLECTS.LAT', commit_changes=commit_changes) - - parse_dict_file(dict_file=words_folder + 'DICTLINE.GEN', commit_changes=commit_changes) - diff --git a/doll/__init__.py b/doll/__init__.py new file mode 100644 index 0000000..dd0ae23 --- /dev/null +++ b/doll/__init__.py @@ -0,0 +1 @@ +__author__ = 'Matthew' diff --git a/doll/db_input_parser/__init__.py b/doll/db_input_parser/__init__.py new file mode 100644 index 0000000..3477e53 --- /dev/null +++ b/doll/db_input_parser/__init__.py @@ -0,0 +1,40 @@ +__author__ = 'Matthew' + +import os + +from db_input_parser.add_database_types import create_type_contents +from db_input_parser.parse_dictionary import parse_dict_file +from doll.db_input_parser.parse_inflections import parse_inflect_file + + +def parse_all_inputs(words_folder, commit_changes): + """Creates the database and parses all the inputs""" + + # Add a trailing slash if necessary + if (words_folder[-1:] != '/'): + words_folder += '/' + + # First check that our words folder exists + if not os.path.isdir(words_folder): + print('Cannot find words_folder at {0}! Exiting...'.format(words_folder)) + return + + # And then that our input files exist + files_to_find = ['INFLECTS.LAT', 'DICTLINE.GEN'] + error_string = ', '.join([f for f in files_to_find if not os.path.isfile(words_folder + f)]) + + if not error_string == '': + print('Unable to find the following file(s): ' + error_string + '. Exiting...') + return + + '''if os.path.isfile(config['db_file']): + if not input('Database file exists, overwrite? ([Y]es/ No)')[:1] == 'Y': + print('Database file exists, exiting...') + return''' + + create_type_contents() + + parse_inflect_file(inflect_file=words_folder + 'INFLECTS.LAT', commit_changes=commit_changes) + + parse_dict_file(dict_file=words_folder + 'DICTLINE.GEN', commit_changes=commit_changes) + diff --git a/db_input_parser/add_database_types.py b/doll/db_input_parser/add_database_types.py similarity index 99% rename from db_input_parser/add_database_types.py rename to doll/db_input_parser/add_database_types.py index 792e6ad..d44529c 100644 --- a/db_input_parser/add_database_types.py +++ b/doll/db_input_parser/add_database_types.py @@ -5,7 +5,7 @@ __author__ = 'Matthew Badger' -from doll_db.model import * +from doll.doll_db import * # Add the basic database types @@ -186,4 +186,6 @@ def create_type_contents(): Connection.session.add(Mood(code='INF', name='Infinitive', description='')) Connection.session.add(Mood(code='PPL', name='Participle', description='')) + Connection.session.add(Language(code='E', name='English', description='English translations from Words')) + Connection.session.commit() diff --git a/db_input_parser/parse_dictionary.py b/doll/db_input_parser/parse_dictionary.py similarity index 99% rename from db_input_parser/parse_dictionary.py rename to doll/db_input_parser/parse_dictionary.py index 06728d5..4bc189d 100644 --- a/db_input_parser/parse_dictionary.py +++ b/doll/db_input_parser/parse_dictionary.py @@ -1,6 +1,6 @@ __author__ = 'Matthew Badger' -from doll_db.model import * +from doll.doll_db import * def parse_dict_file(dict_file, commit_changes=False): diff --git a/db_input_parser/parse_inflections.py b/doll/db_input_parser/parse_inflections.py similarity index 99% rename from db_input_parser/parse_inflections.py rename to doll/db_input_parser/parse_inflections.py index b771c8a..c215bb4 100644 --- a/db_input_parser/parse_inflections.py +++ b/doll/db_input_parser/parse_inflections.py @@ -1,6 +1,6 @@ __author__ = 'Matthew Badger' -from doll_db.model import * +from doll.doll_db import * """Parses the inflections input file. diff --git a/doll/doll_db/__init__.py b/doll/doll_db/__init__.py new file mode 100644 index 0000000..371088e --- /dev/null +++ b/doll/doll_db/__init__.py @@ -0,0 +1,27 @@ +__author__ = 'Matthew Badger' + +from sqlalchemy import engine_from_config +from sqlalchemy.orm import sessionmaker +from sqlalchemy.ext.declarative import declarative_base + +from doll.doll_db.config import config + +Base = declarative_base() + + +'''Connection class + + Connects to the database in the root folder of the application + +''' + +# Connects to the database +class Connection: + __engine = engine_from_config(config, echo=False) + + Base.metadata.create_all(__engine) + + __Session = sessionmaker() + __Session.configure(bind=__engine) + + session = __Session() \ No newline at end of file diff --git a/doll/doll_db/config.py b/doll/doll_db/config.py new file mode 100644 index 0000000..74fda86 --- /dev/null +++ b/doll/doll_db/config.py @@ -0,0 +1,6 @@ +config = { + 'db_file': 'doll_db/doll.db', + 'sqlalchemy.url': 'sqlite:///doll_db/doll.db', + 'sqlalchemy.pool_recycle': '50', + 'sqlalchemy.echo': 'false' +} \ No newline at end of file diff --git a/doll_db/model.py b/doll/doll_db/model.py similarity index 96% rename from doll_db/model.py rename to doll/doll_db/model.py index f5c6acd..07f5356 100644 --- a/doll_db/model.py +++ b/doll/doll_db/model.py @@ -23,11 +23,11 @@ __author__ = 'Matthew Badger' -from doll_db.config import config -from sqlalchemy import engine_from_config, Column, Integer, String, ForeignKey, Boolean, Unicode -from sqlalchemy.orm import relationship, backref, sessionmaker -from sqlalchemy.ext.declarative import declarative_base, declared_attr +from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, Unicode +from sqlalchemy.orm import relationship, backref +from sqlalchemy.ext.declarative import declared_attr +from doll.doll_db import Base """Basic Type Classes @@ -54,8 +54,6 @@ def __tablename__(self): name = Column(String(50)) description = Column(String(300)) -Base = declarative_base() - class PartOfSpeech(TypeBase, Base): """Elements of speech such as a noun. Helper elements used in @@ -160,6 +158,11 @@ class VerbKind(TypeBase, Base): """Kinds of verbs""" +# Language, not used by Words and currently only contains English +class Language(TypeBase, Base): + """Languages for translation""" + + """Inflection Record Classes. @@ -519,6 +522,30 @@ class Stem(Base): entry = relationship('Entry', backref=backref('dictionary_stem')) + +''' + +Start of a translation model, but we need groups... + +# Translation +class Translation(Base): + """A translation of a word in a given language""" + __tablename__ = 'dictionary_translation' + + id = Column(Integer, primary_key=True, autoincrement=True) + + entry_id = Column(Integer, ForeignKey('dictionary_entry.id', + name='FK_dictionary_translation_entry_id')) + + language_id = Column(Integer, ForeignKey('type_language.id', + name='FK_dictionary_translation_language_id')) + + # Relationships + entry = relationship('Entry', backref=backref('dictionary_translation')) + language = relationship('Language', backref=backref('dictionary_translation')) +''' + + # Noun Entry class NounEntry(Base): """Noun entry in the dictionary""" @@ -716,25 +743,4 @@ class InterjectionEntry(Base): name='FK_dictionary_interjection_entry_id')) # Relationships - entry = relationship('Entry', backref=backref('dictionary_interjection')) - - -''' - - Connection class - - Connects to the database in the root folder of the application - -''' - - -# Connects to the database -class Connection: - __engine = engine_from_config(config, echo=False) - - Base.metadata.create_all(__engine) - - __Session = sessionmaker() - __Session.configure(bind=__engine) - - session = __Session() \ No newline at end of file + entry = relationship('Entry', backref=backref('dictionary_interjection')) \ No newline at end of file diff --git a/parse_test.py b/doll/parse_test.py similarity index 99% rename from parse_test.py rename to doll/parse_test.py index ffb7c03..b978255 100644 --- a/parse_test.py +++ b/doll/parse_test.py @@ -1,8 +1,9 @@ __author__ = 'Matthew Badger' -from doll_db.model import * from sqlalchemy import func, or_, and_ +from doll.doll_db import * + session = Connection.session diff --git a/doll_db/__init__.py b/doll_db/__init__.py deleted file mode 100644 index f762ed8..0000000 --- a/doll_db/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'Matthew Badger' diff --git a/doll_db/config.py b/doll_db/config.py deleted file mode 100644 index 8fdddec..0000000 --- a/doll_db/config.py +++ /dev/null @@ -1,5 +0,0 @@ -config = { - 'sqlalchemy.url':'sqlite:///doll.db', - 'sqlalchemy.pool_recycle':'50', - 'sqlalchemy.echo':'false' -} \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0d7bc22 --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +"""DoLL project""" +from setuptools import find_packages, setup + +setup(name = 'DoLL', + version = '0.1', + description = "Database of Latin Lexicon.", + long_description = "A database of the Latin lexicon, generated from the input files for Whitaker's Words.", + author="Matthew Badger", + url="https://github.com/badge/doll", + license = "Apache", + packages=find_packages() + ) \ No newline at end of file