Skip to content
Snippets Groups Projects
Commit ab61355a authored by dcz2's avatar dcz2
Browse files

Make reset_db great again

parent d520dc78
Branches
Tags
No related merge requests found
......@@ -3,3 +3,4 @@
*/migrations/*_auto_*.py
/.datastore/
/.idea/
/import.log
#! /usr/bin/python
# -*- coding: utf-8 -*-
import zipfile
from django.core.management.base import BaseCommand
......@@ -93,13 +94,14 @@ class Command(BaseCommand):
import_plWordnet()
def import_plWordnet():
xml_file = os.path.join(BASE_DIR, 'data', 'plwordnet', 'plwordnet_2_1.xml')
xml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), xml_file)
wordnet_dir = os.path.join(BASE_DIR, 'data', 'plwordnet')
zipped_xml_file = os.path.join(wordnet_dir, 'plwordnet_2_1.xml.zip')
parser = make_parser()
parser.setContentHandler(PlWNHandler())
print("Parsing Wordnet...")
parser.parse(xml_path)
with zipfile.ZipFile(zipped_xml_file, 'r') as zip_file:
parser.parse(zip_file.open("data/plwordnet/plwordnet_2_1.xml"))
print("...DONE")
print()
......@@ -140,12 +142,14 @@ def import_plWordnet():
i += 1
try:
child = Synset.objects.get(id=child_id)
parents = [Synset.objects.get(id=parent_id) for parent_id in parent_ids]
except:
print('************', child_id, parent_ids)
except Synset.DoesNotExist:
print(f'************ Missing Synset {child_id}')
continue
parents = list(Synset.objects.filter(id__in=parent_ids).only("id"))
missing_parent_ids = set(parent_ids) - {p.id for p in parents}
if missing_parent_ids:
print(f'************ Missing parent Synsets for {child_id}: {missing_parent_ids}')
if i % 2000 == 0:
print(i, child, parents)
child.hypernyms.add(*parents)
child.save()
print("...DONE")
#!/bin/bash
sudo su postgres -c "dropdb shellvalier"
sudo su postgres -c "createdb shellvalier -E UTF8 -T template0 -l pl_PL.utf8"
set -e
python manage.py reset_db --noinput
# reset the migrations since we create the DB from scratch
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
......@@ -10,7 +11,7 @@ find . -path "*/migrations/*.pyc" -delete
python manage.py makemigrations
python manage.py migrate
rm import.log
rm import.log || true
time python manage.py start_import
time python manage.py import_expansions
......@@ -21,7 +22,7 @@ head import.log
wc import.log
#python manage.py check_descriptions
python manage.py generate_semantics_css
#python manage.py generate_semantics_css
# TODO dev only!!!
python manage.py shell -c "from django.contrib.auth.models import User; User.objects.create_superuser('shell', '', 'valier')"
......@@ -71,7 +71,6 @@ def import_constants():
import_phrase_attributes()
import_lemma_operators()
import_modification_types()
pass
def import_poses():
poses = [u'unk', u'adj', u'noun', u'adv', u'verb']
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment