Skip to content

Commit

Permalink
Fixed issue #44 : Added bold.
Browse files Browse the repository at this point in the history
Warning : This change is breaking the former data model
  • Loading branch information
PonteIneptique committed Mar 27, 2018
1 parent a944b4b commit 474bf54
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 406 deletions.
4 changes: 3 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import config
from flask_migrate import Migrate

basedir = os.path.abspath(os.path.dirname(__file__))
db = SQLAlchemy()

migrate = Migrate(db=db)

def create_app(config_name="dev"):
""" Create the application """
Expand All @@ -22,6 +23,7 @@ def create_app(config_name="dev"):

# Set up extensions
db.init_app(app)
migrate.init_app(app)
#assets_env = Environment(app)

# Register Jinja template functions
Expand Down
16 changes: 14 additions & 2 deletions app/models/linguistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ class WordToken(db.Model):
label_uniform = db.Column(db.String(64))
POS = db.Column(db.String(64))
morph = db.Column(db.String(64))
context = db.Column(db.String(512))
left_context = db.Column(db.String(512))
right_context = db.Column(db.String(512))

CONTEXT_LEFT = 3
CONTEXT_RIGHT = 3
Expand Down Expand Up @@ -498,7 +499,9 @@ def add_batch(corpus_id, word_tokens_dict, context_left=None, context_right=None
label_uniform=unidecode.unidecode(token.get("lemma", token.get("lemmas"))),
POS=token.get("POS", token.get("pos")),
morph=token.get("morph", None),
context=" ".join(previous_token + [token.get("form", token.get("tokens"))] + next_token),
#context=" ".join(previous_token + [token.get("form")] + next_token),
left_context=" ".join(previous_token),
right_context=" ".join(next_token),
corpus=corpus_id,
order_id=i
)
Expand Down Expand Up @@ -562,6 +565,15 @@ def update(corpus_id, token_id, lemma=None, POS=None, morph=None):
db.session.commit()
return token, record

@property
def context(self):
""" Reformed version of former code for the context column"""
return " ".join([
tok
for tok in [self.left_context, self.form, self.right_context]
if tok
])

@staticmethod
def get_similar_to_record(change_record):
""" Get tokens which shares similarity with ChangeRecord
Expand Down
10 changes: 7 additions & 3 deletions app/templates/macros/tokens_macros.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

{%- macro token_context(token) %}
{{ token.left_context }} <b>{{ token.form }}</b> {{ token.right_context }}
{% endmacro -%}

{% macro table(tokens, corpus, editable=False, tracking=False, checkbox=False, record=None, similar=False) %}
{% if editable %}
{%- if checkbox %}
Expand All @@ -25,7 +29,7 @@ <h3>Save checked similar lemma</h3>
</td>
<td {% if not checkbox %}contenteditable="true" class="token_pos"{% endif %}>{{token.POS}}</td>
<td {% if not checkbox %}contenteditable="true" class="token_morph"{% endif %}>{{token.morph}}</td>
<td class="small">{{token.context}}</td>
<td class="small">{{token_context(token)}}</td>
{%- if similar %}<td><a class="similar-link" href="{{url_for('main.tokens_similar_to_token', token_id=token.id, corpus_id=corpus.id, mode='partial')}}"><span class="badge badge-secondary">{{token.similar}}</span></a></td>{% endif -%}
{%- if checkbox %}<td><input class="form-check word-token" type="checkbox" checked="checked" value="{{token.id}}" /></td>
{% else%}<td><a class="save" href="{{url_for("main.tokens_edit_single", corpus_id=corpus.id, token_id=token.id)}}">Save</a></td>
Expand Down Expand Up @@ -172,7 +176,7 @@ <h3>Save checked similar lemma</h3>
<tr>
<td class="small">{{token.created_on}}</td>
<td>{{token.form}}</td>
<td class="small">{{token.word_token.context}}</td>
<td class="small">{{token_context(token.word_token)}}</td>
<td class="bg-warning">{{token.lemma}}</td>
<td class="bg-warning">{{token.POS}}</td>
<td class="bg-warning">{{token.morph}}</td>
Expand All @@ -199,7 +203,7 @@ <h3>Save checked similar lemma</h3>
<td class="token_lemma">{{token.lemma}}</td>
<td class="token_pos">{{token.POS}}</td>
<td class="token_morph">{{token.morph}}</td>
<td class="small">{{token.context}}</td>
<td class="small">{{token_context(token)}}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
5 changes: 3 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
from flask_script import Manager
from flask_migrate import MigrateCommand
from config import Config
from tests.db_fixtures import add_corpus

from app import create_app, db
from app import create_app, db, migrate
# from app.models import Role, User


Expand Down Expand Up @@ -47,6 +47,7 @@ def fixtures_to_db():
Recreates a local database. You probably should not use this on
production.
"""
from tests.db_fixtures import add_corpus
add_corpus(
"wauchier", db, with_token=True, tokens_up_to=None,
with_allowed_lemma=True, partial_allowed_lemma=False,
Expand Down
105 changes: 70 additions & 35 deletions tests/db_fixtures/floovant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,76 @@

Floovant = Corpus(name="Floovant", id=2)
FloovantTokens = [
WordToken(corpus=Floovant.id, form="SOIGNORS", lemma="seignor", context="SOIGNORS or escoutez que", label_uniform="seignor", morph="NOMB.=p|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="or", lemma="or4", context="SOIGNORS or escoutez que Dés", label_uniform="or4", morph="DEGRE=-"),
WordToken(corpus=Floovant.id, form="escoutez", lemma="escouter", context="SOIGNORS or escoutez que Dés vos", label_uniform="escouter", morph="MODE=imp|PERS.=2|NOMB.=p"),
WordToken(corpus=Floovant.id, form="que", lemma="que4", context="SOIGNORS or escoutez que Dés vos soit", label_uniform="que4", morph="_"),
WordToken(corpus=Floovant.id, form="Dés", lemma="dieu", context="or escoutez que Dés vos soit amis", label_uniform="dieu", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="vos", lemma="vos1", context="escoutez que Dés vos soit amis III", label_uniform="vos1", morph="PERS.=2|NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="soit", lemma="estre1", context="que Dés vos soit amis III vers", label_uniform="estre1", morph="MODE=sub|TEMPS=pst|PERS.=3|NOMB.=s"),
WordToken(corpus=Floovant.id, form="amis", lemma="ami", context="Dés vos soit amis III vers de", label_uniform="ami", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="III", lemma="trois1", context="vos soit amis III vers de bone", label_uniform="trois1", morph="NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="vers", lemma="vers1", context="soit amis III vers de bone estoire", label_uniform="vers1", morph="NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="de", lemma="de", context="amis III vers de bone estoire se", label_uniform="de", morph="_"),
WordToken(corpus=Floovant.id, form="bone", lemma="bon", context="III vers de bone estoire se je", label_uniform="bon", morph="NOMB.=s|GENRE=f|CAS=r|DEGRE=p"),
WordToken(corpus=Floovant.id, form="estoire", lemma="estoire1", context="vers de bone estoire se je les", label_uniform="estoire1", morph="NOMB.=s|GENRE=f|CAS=r"),
WordToken(corpus=Floovant.id, form="se", lemma="si", context="de bone estoire se je les vos", label_uniform="si", morph="DEGRE=-"),
WordToken(corpus=Floovant.id, form="je", lemma="je", context="bone estoire se je les vos devis", label_uniform="je", morph="PERS.=1|NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="les", lemma="il", context="estoire se je les vos devis Dou", label_uniform="il", morph="PERS.=3|NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="vos", lemma="vos1", context="se je les vos devis Dou premier", label_uniform="vos1", morph="PERS.=2|NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="devis", lemma="deviser", context="je les vos devis Dou premier roi", label_uniform="deviser", morph="MODE=ind|TEMPS=pst|PERS.=1|NOMB.=s"),
WordToken(corpus=Floovant.id, form="Dou", lemma="de+le", context="les vos devis Dou premier roi de", label_uniform="de+le", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="premier", lemma="premier", context="vos devis Dou premier roi de France", label_uniform="premier", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="roi", lemma="roi2", context="devis Dou premier roi de France qui", label_uniform="roi2", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="de", lemma="de", context="Dou premier roi de France qui crestïens", label_uniform="de", morph="_"),
WordToken(corpus=Floovant.id, form="France", lemma="france", context="premier roi de France qui crestïens devint", label_uniform="france", morph="NOMB.=s|GENRE=f|CAS=r"),
WordToken(corpus=Floovant.id, form="qui", lemma="qui", context="roi de France qui crestïens devint Cil", label_uniform="qui", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="crestïens", lemma="crestiien", context="de France qui crestïens devint Cil ot", label_uniform="crestiien", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="devint", lemma="devenir", context="France qui crestïens devint Cil ot non", label_uniform="devenir", morph="MODE=ind|TEMPS=psp|PERS.=3|NOMB.=s"),
WordToken(corpus=Floovant.id, form="Cil", lemma="cel", context="qui crestïens devint Cil ot non Cloovis", label_uniform="cel", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="ot", lemma="avoir", context="crestïens devint Cil ot non Cloovis si", label_uniform="avoir", morph="MODE=ind|TEMPS=psp|PERS.=3|NOMB.=s"),
WordToken(corpus=Floovant.id, form="non", lemma="nom", context="devint Cil ot non Cloovis si com", label_uniform="nom", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="Cloovis", lemma="clovis", context="Cil ot non Cloovis si com truis", label_uniform="clovis", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="si", lemma="si", context="ot non Cloovis si com truis en", label_uniform="si", morph="DEGRE=-"),
WordToken(corpus=Floovant.id, form="com", lemma="come1", context="non Cloovis si com truis en escrit", label_uniform="come1", morph="_"),
WordToken(corpus=Floovant.id, form="truis", lemma="trover", context="Cloovis si com truis en escrit", label_uniform="trover", morph="MODE=ind|TEMPS=pst|PERS.=1|NOMB.=s"),
WordToken(corpus=Floovant.id, form="en", lemma="en1", context="si com truis en escrit", label_uniform="en1", morph="_"),
WordToken(corpus=Floovant.id, form="escrit", lemma="escrit", context="com truis en escrit", label_uniform="escrit", morph="NOMB.=s|GENRE=m|CAS=r")
WordToken(corpus=Floovant.id, form="SOIGNORS", lemma="seignor", left_context="", right_context="or escoutez que",
label_uniform="seignor", morph="NOMB.=p|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="or", lemma="or4", left_context="SOIGNORS", right_context="escoutez que Dés",
label_uniform="or4", morph="DEGRE=-"),
WordToken(corpus=Floovant.id, form="escoutez", lemma="escouter", left_context="SOIGNORS or",
right_context="que Dés vos", label_uniform="escouter", morph="MODE=imp|PERS.=2|NOMB.=p"),
WordToken(corpus=Floovant.id, form="que", lemma="que4", left_context="SOIGNORS or escoutez",
right_context="Dés vos soit", label_uniform="que4", morph="_"),
WordToken(corpus=Floovant.id, form="Dés", lemma="dieu", left_context="or escoutez que",
right_context="vos soit amis", label_uniform="dieu", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="vos", lemma="vos1", left_context="escoutez que Dés",
right_context="soit amis III", label_uniform="vos1", morph="PERS.=2|NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="soit", lemma="estre1", left_context="que Dés vos",
right_context="amis III vers", label_uniform="estre1", morph="MODE=sub|TEMPS=pst|PERS.=3|NOMB.=s"),
WordToken(corpus=Floovant.id, form="amis", lemma="ami", left_context="Dés vos soit", right_context="III vers de",
label_uniform="ami", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="III", lemma="trois1", left_context="vos soit amis",
right_context="vers de bone", label_uniform="trois1", morph="NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="vers", lemma="vers1", left_context="soit amis III",
right_context="de bone estoire", label_uniform="vers1", morph="NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="de", lemma="de", left_context="amis III vers", right_context="bone estoire se",
label_uniform="de", morph="_"),
WordToken(corpus=Floovant.id, form="bone", lemma="bon", left_context="III vers de", right_context="estoire se je",
label_uniform="bon", morph="NOMB.=s|GENRE=f|CAS=r|DEGRE=p"),
WordToken(corpus=Floovant.id, form="estoire", lemma="estoire1", left_context="vers de bone",
right_context="se je les", label_uniform="estoire1", morph="NOMB.=s|GENRE=f|CAS=r"),
WordToken(corpus=Floovant.id, form="se", lemma="si", left_context="de bone estoire", right_context="je les vos",
label_uniform="si", morph="DEGRE=-"),
WordToken(corpus=Floovant.id, form="je", lemma="je", left_context="bone estoire se", right_context="les vos devis",
label_uniform="je", morph="PERS.=1|NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="les", lemma="il", left_context="estoire se je", right_context="vos devis Dou",
label_uniform="il", morph="PERS.=3|NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="vos", lemma="vos1", left_context="se je les", right_context="devis Dou premier",
label_uniform="vos1", morph="PERS.=2|NOMB.=p|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="devis", lemma="deviser", left_context="je les vos",
right_context="Dou premier roi", label_uniform="deviser", morph="MODE=ind|TEMPS=pst|PERS.=1|NOMB.=s"),
WordToken(corpus=Floovant.id, form="Dou", lemma="de+le", left_context="les vos devis",
right_context="premier roi de", label_uniform="de+le", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="premier", lemma="premier", left_context="vos devis Dou",
right_context="roi de France", label_uniform="premier", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="roi", lemma="roi2", left_context="devis Dou premier",
right_context="de France qui", label_uniform="roi2", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="de", lemma="de", left_context="Dou premier roi",
right_context="France qui crestïens", label_uniform="de", morph="_"),
WordToken(corpus=Floovant.id, form="France", lemma="france", left_context="premier roi de",
right_context="qui crestïens devint", label_uniform="france", morph="NOMB.=s|GENRE=f|CAS=r"),
WordToken(corpus=Floovant.id, form="qui", lemma="qui", left_context="roi de France",
right_context="crestïens devint Cil", label_uniform="qui", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="crestïens", lemma="crestiien", left_context="de France qui",
right_context="devint Cil ot", label_uniform="crestiien", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="devint", lemma="devenir", left_context="France qui crestïens",
right_context="Cil ot non", label_uniform="devenir", morph="MODE=ind|TEMPS=psp|PERS.=3|NOMB.=s"),
WordToken(corpus=Floovant.id, form="Cil", lemma="cel", left_context="qui crestïens devint",
right_context="ot non Cloovis", label_uniform="cel", morph="NOMB.=s|GENRE=m|CAS=n"),
WordToken(corpus=Floovant.id, form="ot", lemma="avoir", left_context="crestïens devint Cil",
right_context="non Cloovis si", label_uniform="avoir", morph="MODE=ind|TEMPS=psp|PERS.=3|NOMB.=s"),
WordToken(corpus=Floovant.id, form="non", lemma="nom", left_context="devint Cil ot", right_context="Cloovis si com",
label_uniform="nom", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="Cloovis", lemma="clovis", left_context="Cil ot non",
right_context="si com truis", label_uniform="clovis", morph="NOMB.=s|GENRE=m|CAS=r"),
WordToken(corpus=Floovant.id, form="si", lemma="si", left_context="ot non Cloovis", right_context="com truis en",
label_uniform="si", morph="DEGRE=-"),
WordToken(corpus=Floovant.id, form="com", lemma="come1", left_context="non Cloovis si",
right_context="truis en escrit", label_uniform="come1", morph="_"),
WordToken(corpus=Floovant.id, form="truis", lemma="trover", left_context="Cloovis si com",
right_context="en escrit", label_uniform="trover", morph="MODE=ind|TEMPS=pst|PERS.=1|NOMB.=s"),
WordToken(corpus=Floovant.id, form="en", lemma="en1", left_context="si com truis", right_context="escrit",
label_uniform="en1", morph="_"),
WordToken(corpus=Floovant.id, form="escrit", lemma="escrit", left_context="com truis en", right_context="",
label_uniform="escrit", morph="NOMB.=s|GENRE=m|CAS=r"),

]
FloovantAllowedPOS = [
Expand Down
Loading

0 comments on commit 474bf54

Please sign in to comment.