diff --git a/Digraph.gv b/Digraph.gv index 29e7a3b..b36bc31 100644 --- a/Digraph.gv +++ b/Digraph.gv @@ -1,34 +1,34 @@ // The Round Table digraph { + graph [rankdir=LR] + foarte -> bun + bun -> Unul + cu -> vapor + un -> vapor + vapor -> Unul + plin -> vapor + de -> "refugiați" + "refugiați" -> plin + bombardat -> plin + undeva -> bombardat + "în" -> Mediterana + Mediterana -> bombardat // The Round Table { - rank=same - Textul -> de - de -> dedesubt - dedesubt -> suna - suna -> "" - "" -> FRATELE - FRATELE -> CEL - CEL -> MARE - MARE -> ESTE - ESTE -> CU - CU -> OCHII - OCHII -> PE - PE -> TINE - TINE -> "." - Textul -> suna - de -> dedesubt - dedesubt -> Textul - suna -> "." - "" -> suna - FRATELE -> ESTE - CEL -> MARE - MARE -> FRATELE - ESTE -> suna - CU -> ESTE - OCHII -> ESTE - PE -> TINE - TINE -> ESTE - "." -> suna + edge [style=invis] + Unul -> foarte + foarte -> bun + bun -> cu + cu -> un + un -> vapor + vapor -> plin + plin -> de + de -> "refugiați" + "refugiați" -> "," + "," -> bombardat + bombardat -> undeva + undeva -> "în" + "în" -> Mediterana + Mediterana -> "." } } diff --git a/Digraph.gv.svg b/Digraph.gv.svg index 02a0d0d..51955b6 100644 --- a/Digraph.gv.svg +++ b/Digraph.gv.svg @@ -4,253 +4,185 @@ - - - - + + + + -Textul - -Textul +foarte + +foarte - + -de - -de +bun + +bun - + -Textul->de - - - - - -suna - -suna - - - -Textul->suna - - +foarte->bun + + - + + -dedesubt - -dedesubt +Unul + +Unul - + -de->dedesubt - - +bun->Unul + + - - -de->dedesubt - - - - - -dedesubt->Textul - - - - - -dedesubt->suna - - + + +cu + +cu + + + - - - - - -suna-> - - - - - -. - -. +vapor + +vapor - - -suna->. - - - - - -->suna - - + + +cu->vapor + + - + -FRATELE - -FRATELE +un + +un - + + -->FRATELE - - +vapor->Unul + + - + -CEL - -CEL +plin + +plin - - -FRATELE->CEL - - - - - -ESTE - -ESTE + + + +un->vapor + + - - -FRATELE->ESTE - - + + + +plin->vapor + + - + -MARE - -MARE - - - -CEL->MARE - - +de + +de - - -CEL->MARE - - + + + +refugiați + +refugiați - - -MARE->FRATELE - - + + +de->refugiați + + - + + -MARE->ESTE - - +refugiați->plin + + - - -ESTE->suna - - + + +, + +, - + + -CU - -CU +bombardat + +bombardat - + -ESTE->CU - - - - - -CU->ESTE - - +bombardat->plin + + - + -OCHII - -OCHII +undeva + +undeva - + + -CU->OCHII - - +undeva->bombardat + + - - -OCHII->ESTE - - - - + -PE - -PE - - - -OCHII->PE - - +în + +în - + + -TINE - -TINE - - - -PE->TINE - - +Mediterana + +Mediterana - - -PE->TINE - - - - - -TINE->ESTE - - + + +în->Mediterana + + - - -TINE->. - - + + + +Mediterana->bombardat + + - - -.->suna - - + + +. + +. + + diff --git a/app.py b/app.py index c24f0d6..0b6c722 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,8 @@ import io -import spacy import csv +# import spacy +# from spacy import displacy from flask import Flask, render_template, request -from spacy import displacy from graphviz import Digraph from conllu import parse_incr from conllu import parse @@ -13,72 +13,88 @@ @app.route('/', methods = ['GET', 'POST']) def index(): - conllu = '' - svg = '' - - if request.method == 'POST': - if request.form['func'] == '1': - conllu = request.form['conllu'] - print(conllu) - svg = propDisplaySpacy(conllu) - return render_template('index.html', conllu = conllu, svg = svg) - - elif request.form['func'] == '2': - conllu = request.form['conllu'] - print(conllu) - svg = propDisplayGraph(conllu) - return render_template('index.html', conllu = conllu, svg = svg) - - return render_template('index.html', conllu = conllu) +@app.route('/GraphvizConvertor.html', methods = ['GET', 'POST']) +def graphConvertor(): + conllu = '' -def propDisplayGraph(connlu): - - sentences = parse(connlu) - - listOfID = [] - listOfHead = [] - listOfString = [] - - sentence = sentences[0] - for i in range(0,len(sentence)): - token = sentence[i] - listOfID.append(token['id']) - listOfHead.append(token['head'] - 1) - listOfString.append(token['form']) + if request.method == 'POST': + conllu = request.form['conllu'] + svg = propDisplayGraph(conllu) + return render_template('GraphvizConvertor.html', conllu = conllu, svg = svg) - dot = Digraph(comment='The Round Table', format = 'svg') + return render_template('GraphvizConvertor.html') - subgraph = Digraph(comment='The Round Table') - subgraph.attr(rank='same') - - for i in range(0,len(listOfHead) - 1): - subgraph.edge(str(listOfString[i]), str(listOfString[i + 1])) - for i in range(0,len(listOfHead)): - if str(listOfString[listOfHead[i]]) == '0': - continue - else: - subgraph.edge(str(listOfString[i]), str(listOfString[listOfHead[i]])) - continue +@app.route('/SpacyConvertor.html', methods = ['GET', 'POST']) +def spaCyConvertor(): + if request.method == 'POST': + prop = request.form['prop'] + svg = propDisplaySpacy(prop) + return render_template('SpacyConvertor.html', prop = prop, svg = svg) - dot.subgraph(subgraph) + return render_template('SpacyConvertor.html') - dot.format = 'svg' - dot.render() - svg = dot.pipe().decode('utf-8').strip() - return svg +def propDisplayGraph(connlu): -def propDisplaySpacy(conllu): - nlp = spacy.load("ro_core_news_lg") - doc1 = nlp(conllu) - options = {"compact": True, "bg": "white","color": "black", "font": "Source Sans Pro"} - svg = displacy.render(doc1, style="dep", page=False, options=options) - return svg + try: + + sentences = parse(connlu) + + listOfID = [] + listOfHead = [] + listOfString = [] + listOfUPOS = [] + + sentence = sentences[0] + for i in range(0,len(sentence)): + token = sentence[i] + listOfID.append(token['id'] - 1) + listOfHead.append(token['head'] - 1) + listOfString.append(token['form']) + listOfUPOS.append(token['upos']) + + dot = Digraph(comment='The Round Table', format = 'svg') + dot.graph_attr['rankdir'] = 'LR' + + subgraph = Digraph(comment='The Round Table') + # subgraph.attr(rank='same') + subgraph.edge_attr['style'] = 'invis' + + for i in range(0,len(listOfHead) - 1): + subgraph.edge(str(listOfString[i]), str(listOfString[i + 1])) + + for i in range(0,len(listOfHead) - 1): + if str(listOfHead[i]) == '-1': + continue + elif str(listOfUPOS[i]) == 'PUNCT': + continue + else: + dot.edge(str(listOfString[i]), str(listOfString[listOfHead[i]])) + + dot.subgraph(subgraph) + + dot.format = 'svg' + dot.render() + svg = dot.pipe().decode('utf-8').strip() + return svg + except: + return "Incorrect format" + + +# def propDisplaySpacy(prop): +# if prop != None: +# nlp = spacy.load("ro_core_news_sm") +# doc1 = nlp(prop) +# options = {"compact": True, "bg": "white","color": "black", "font": "Source Sans Pro"} +# svg = displacy.render(doc1, style="dep", page=False, options=options) +# return svg +# else: +# return "Incorrect format" if __name__ == "__main__": app.run(debug=True) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2489061 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,161 @@ +colorful==0.5.4 +conll-df==0.0.4 +conllu==4.4 +ConllViewer==1.0.0 +cryptography==3.4.7 +cycler==0.10.0 +cymem==2.0.5 +decorator==4.4.2 +defusedxml==0.7.1 +deprecation==2.1.0 +diagrams==0.20.0 +Distance==0.1.3 +docx2txt==0.8 +EbookLib==0.17.1 +entrypoints==0.3 +et-xmlfile==1.1.0 +extract-msg==0.23.1 +filelock==3.0.12 +Flask==1.1.2 +flatbuffers==1.12 +gast==0.4.0 +gensim==3.8.0 +gitdb==4.0.7 +GitPython==3.1.14 +graphviz==0.16 +grpcio==1.34.1 +h11==0.9.0 +h2==3.2.0 +h5py==3.1.0 +hpack==3.0.0 +hstspreload==2020.12.22 +htbuilder==0.3.0 +httpcore==0.9.1 +httpx==0.13.3 +hyperframe==5.2.0 +idna==2.10 +IMAPClient==2.1.0 +install==1.3.4 +ipykernel==5.5.3 +ipython==7.22.0 +ipython-genutils==0.2.0 +ipywidgets==7.6.3 +isort==5.8.0 +iteration-utilities==0.11.0 +itsdangerous==1.1.0 +jedi==0.18.0 +Jinja2==2.11.3 +joblib==1.0.1 +kiwisolver==1.3.1 +lazy-object-proxy==1.6.0 +lxml==4.6.3 +Markdown==3.3.4 +MarkupSafe==1.1.1 +matplotlib==3.4.1 +mccabe==0.6.1 +missingno==0.5.0 +mistune==0.8.4 +murmurhash==1.0.5 +nbclassic==0.2.7 +nbclient==0.5.3 +nbconvert==6.0.7 +nbformat==5.1.3 +nest-asyncio==1.5.1 +networkx==2.5.1 +nltk==3.6.1 +nose==1.3.7 +notebook==6.3.0 +numpy==1.19.5 +oauthlib==3.1.0 +olefile==0.46 +openpyxl==3.0.7 +opt-einsum==3.3.0 +packaging==20.9 +pandas==1.2.4 +pandocfilters==1.4.3 +parso==0.8.2 +pathy==0.4.0 +pdfminer.six==20201018 +pickleshare==0.7.5 +Pillow==8.2.0 +plotly==5.1.0 +pprintpp==0.4.0 +preshed==3.0.5 +prettyprinter==0.18.0 +prometheus-client==0.10.1 +prompt-toolkit==3.0.18 +protobuf==3.15.8 +pyasn1==0.4.8 +pyasn1-modules==0.2.8 +pyconll==3.1.0 +pycparser==2.20 +pycryptodome==3.10.1 +pydantic==1.7.3 +pydeck==0.6.2 +Pygments==2.8.1 +pylint==2.7.4 +pyparsing==2.4.7 +PyPDF2==1.26.0 +pyrouge==0.1.3 +pyrsistent==0.17.3 +python-dateutil==2.8.1 +python-pptx==0.6.18 +pytz==2021.1 +pywinpty==0.5.7 +PyYAML==5.4.1 +pyzmq==22.0.3 +regex==2021.4.4 +requests==2.25.1 +requests-oauthlib==1.3.0 +Reverso-API==0.0.1b3 +reverso-context-api==0.5 +rfc3986==1.5.0 +rouge==1.0.0 +rowordnet==1.1.0 +rsa==4.7.2 +sacremoses==0.0.44 +scikit-learn==0.24.1 +scipy==1.6.2 +seaborn==0.11.1 +selenium==3.141.0 +Send2Trash==1.5.0 +six==1.12.0 +sklearn==0.0 +smart-open==3.0.0 +smmap==4.0.0 +sniffio==1.2.0 +sortedcontainers==2.3.0 +soupsieve==2.2.1 +spacy==3.0.5 +spacy-legacy==3.0.2 +SpeechRecognition==3.8.1 +srsly==2.4.1 +st-annotated-text==1.1.0 +streamlit==0.80.0 +threadpoolctl==2.1.0 +tokenizers==0.10.2 +toml==0.10.2 +tomlkit==0.7.0 +toolz==0.11.1 +tornado==6.1 +tqdm==4.60.0 +traitlets==5.0.5 +transformers==4.5.1 +typer==0.3.2 +typing-extensions==3.7.4.3 +tzlocal==1.5.1 +urllib3==1.26.4 +validators==0.18.2 +wasabi==0.8.2 +watchdog==2.0.2 +wcwidth==0.2.5 +webencodings==0.5.1 +Werkzeug==1.0.1 +widgetsnbextension==3.5.1 +word2vec-keras==0.1 +word2veckeras==0.0.5.2 +wordnet==0.0.1b2 +wrapt==1.12.1 +xlrd==1.2.0 +XlsxWriter==1.3.9 +xmltodict==0.12.0 diff --git a/templates/GraphvizConvertor.html b/templates/GraphvizConvertor.html new file mode 100644 index 0000000..0eee5e3 --- /dev/null +++ b/templates/GraphvizConvertor.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} + +{% block content %} + +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+ +
+ {{svg | safe}} +
+ +{% endblock %} \ No newline at end of file diff --git a/templates/SpacyConvertor.html b/templates/SpacyConvertor.html new file mode 100644 index 0000000..a590802 --- /dev/null +++ b/templates/SpacyConvertor.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} + +{% block content %} + +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+ +
+ {{svg | safe}} +
+ +{% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..a66208e --- /dev/null +++ b/templates/base.html @@ -0,0 +1,47 @@ + + + + +Disambiguation + + + + + + + + + + + + + + +{% block content %} + +{% endblock %} + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index fd2e17b..6be14f5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,22 +1,12 @@ - - - +{% extends 'base.html' %} -Disambiguation +{% block content %} - - - - - - - +{% endblock %} - - - + -
+ - -