3.9.2. WiTTSim Ähnlichkeitssuche¶
Die WiTTSim Ähnlichkeitssuche erlaubt es, zwei Texteingaben miteinander zu vergleichen und den Abstand zu berechnen. Dabei kann entweder ein Text aus WiTTFind kopiert werden und mit einem anderen Text aus dem Nachlass verglichen werden, oder aber mit einem freien Text, z.B. von Goethe, um Wittgensteins Referenzen auf die Weltliteratur zu messen und zu vergleichen.
3.9.2.1. Allgemeines¶
Damit die Ähnlichkeitssuche funktioniert sind folgende Schritte nötig (welche im Folgenden noch detailliert beschrieben werden):
Vorbereiten der Umgebung
Vorberechnen der Vektoren
Starten der Ähnlichkeitssuche
Integration in Wittfind-Web
Alle dafür benötigten Programme und Dateien sind dabei frei verfügbar, außer die Lizenz für Germanet (Deutsche Version von Germanet), einer Synset Datenbank, welche hier für die Extrahierung von Synonymen verwendet wird. Die Lizenz ist am CIS zu Forschungszwecken vorhanden, bei Bedarf bitte an Max Hadersbeck wenden.
3.9.2.2. Vorbereiten der Umgebung¶
Die Vektoren werden in wittsim_data
vorberechnet und anschließend dort in export-data
gespeichert.
3.9.2.2.1. Cluster Modelle¶
Zunächst müssen die Cluster Modelle kopiert werden. Diese liegen im $(HOME) auf CAST2. Dazu in den Ordner deployment
wechseln, dann die Modelle kopieren mit:
make install_cluster_models
3.9.2.2.2. Tree-Tagger¶
Dann muss der Tree-Tagger und die Python-Module installiert werden:
make install-python-modules install-tree-tagger
3.9.2.2.3. MongoDB¶
Zusätzlich muss die MongoDB installiert sein, mit Germanet Daten befüllt sein und laufen:
Install MongoDB
Importiere GermaNet in die MongoDB
Eine Kopie von Germanet ist verfügbar unter dem korpus Ordner, welche im LRZ Sync and Share geteilt werden kann (Kontakt: Max Hadersbeck) Import XML to MongoDB
Starte MongoDB
mkdir mongodb mongod --dbpath ./mongodb &
Entpacke die Germanet Dateien und lade sie in die MongoDB (das kann eine ganze Weile dauern)
python -m pygermanet.mongo_import ./GN_V120/GN_V120_XML/
Überprüfe das Setup der MongoDB + Germanet:
from pygermanet import load_germanet gn = load_germanet() gn.synsets('gehen')
3.9.2.3. Vorberechnen der Vektoren¶
Nun kann das Binary-File der Vektoren berechnet werden. Dafür kann einfach
make generate
aufgerufen werden, welches sowohl die Megavektoren berechnet, das KNN Modell trainiert, sowie im Anschluss unnötige Files löscht.
Sollten nicht alle Aufrufe (z.B. kein Trainieren des KNN Modells) gewünscht sein, können entsprechende Einzelaufrufe gestartet werden (siehe
Makefile
):make vectors make knn make clean_json
3.9.2.4. Starten der Suche¶
Die Suche kann ganz leicht via Kommandozeile gestartet werden. Dafür in den Ordner wittsim/lib
navigieren und in der Datei simveccomp.py
die gewünschten Texte eingeben. Das Programm dann starten mit
python3 simveccomp.py
Achtung: Auch hier muss die MongoDB laufen
sudo service mongod start
überprüft werden kann dies, indem man den Status auf “active (running)” überprüft:
service mongod status
Damit WiTTSim in WittFind integriert werden kann, muss sie in Wittfind-Web integriert werden, wie in den Folgenden Schritten beschrieben (umgesetzt im Masterseminar 2019/20).
3.9.2.5. HTML Files¶
similarity.html
was created using the Bootstrap 4 framework. It was made similar to translator.html because it used multiple features that were needed, such as: card-boxes, form-groups/control (to align the boxes next to each other), and buttons.Our page includes two text boxes where one can enter two different texts and choose the language the two texts use.
This page will also display the similarity calculation result after one presses the “Ähnlichkeit berechnen” button. The similarity of the texts will be calculated in the backend by vectorizing the dictionaries of the two input strings and by determining their difference using cosine similarity.
3.9.2.6. Frontend Integration¶
In order to get access to the frontend of WiTTSim-Web download the following repository: wittfind-web
git clone git@gitlab.cis.uni-muenchen.de:wast/wittfind-web.git git checkout feature/document_overview_in_ranked#1170 git pull
First, changes were made to the
index.html
file in order to integratesimilarity.html
into the webpage. Changes such as:Creation of a drop down menu that displays both
WittSim
andFarben & Musik
underSemantisches Finden
Integration of a css style sheet for the
similarity.html
file by creating a file calledsimilarity.css
→ this file give the shape and size of all the boxes and buttons on our webpage (the text boxes have the same width and the margin from the main box to both text boxes and buttons is the same).
In order to make
similarity.html
visible in the front end, we had to create the javascript filesimilarity.js
that is located into theinclude
folder of the wittfind-web repository.
→ this file contains a method that is responsible for showing thesimilarity.html
template on the wittfind development page in the bootstrap 4 design.Inside the
include
foldersimilarity.js
had to be integrated intomain.js
androuter.js
so that the template could be loaded in the frontend.
3.9.2.7. Frontend / Backend Integration mit jQuery AJAX¶
We recevied a Javascript file called
wittsim-control.js
from Sebastian Still. This file should link the button of thesimilarity.html
and transfer value of the two texts fromsimilarity.html
to the backend, to a method calledsim2texts
in the python fileflaskServer.py
, using AJAX (POST-Request).After similarity calculation is finished in
sim2texts
, this method will send the result back towittsim-coltrol.js
, which will then post the result on thesimilarity.html
page.After receiving the result of the calculation, a new box will appear at the bottom of the
similarity.html
file displaying the result of the similarity calculation. If only one text or even no texts are being provided the result will say ‘No result received’
→ this little box is not visibile at first as it is hidden insimilarity.html
, but appears after the button “Ähnlichkeit berechnen” is pressed because it is also linked towittsim-control.js
.The connection between
similarity.html
,wittsim-control.js
andflaskServer.py
was mainly provided by Sebastian Still and Matthias Lindinger.
3.9.2.8. Backend Umsetzung mit Flask¶
We received a folder called witt-similar. In this folder there was a Flask server file called
server.py
made by Sabine Ullrich. In this file we created a method calledsim2texts
, which calculates the similarity of two texts. This method uses two other classes calledSimVecComp
andSimVec
which can be found in the lib folder of the wittsim repository (calledsimvec.py
andsimveccomp.py
).Before
SimVecComp
could be used correctly we needed to modify some of the methods within this class with Sabine so that it will funciton properly withsim2texts
→ the actual similarity calculation of two texts was executed in thesimveccomp.py
file.As no weights have been provided for the calculation of the similarity vectors (e.g. by tf-idf model) default weights with the value 1 have been used for the calculations.
All the relevant files were pushed to the wittsim repository, and the
sim2texts
method was integrated intoflaskServer.py
, which was the KNN groups flask server.As Max Hadersbeck and the KNN team have set up a CI under
var/www/wittsim
so that the Flask Server can be started and our methodsim2texts
can be called.
3.9.2.9. Mögliche Fehlermeldungen¶
Make sure you set the right PATH for TAGDIR with
export TAGDIR=/full/path/to/wittsim/ext/treetagger
→ remember that you have to write your computer’s full path to wittsim and that you have to do this everytime you reboot your computer, unless you copy the export command above to your
~/.bash_profile
.On linux devices use
make install-tree-tagger-linux
instead ofmake install-tree-tagger
. For this to be sucessful, the three hashtags in tree-tagger.mk, as seen here:#ifeq ($(arch),linux) #tree-tagger-dependencies += tree-tagger-linux-3.2-old5.tar.gz #endif
must be removed. One can find this files in wittsim/make/tree-tagger.mk.
In order to check if the TAGDIR was set correctly use the command
echo $TAGDIR
.Go to
wittsim/ext/treetagger
and unziptree-tagger-linux-3.2.1.tar.gz
with the following commandtar -zxf tree-tagger-linux-3.2.1.tar.gz
PAY ATTENTION: errors during the treetagger installation can occur if you have spaces in the path leading to the wittsim directory.
If there is still an error contact Max Hadersbeck for further instructions.