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

Make reset_db great again

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