remove_single_expr_meanings.py
1.04 KB
# -*- coding:utf-8 -*-
import re
import sys
import time
import jsonpickle
from django.core.management.base import BaseCommand, make_option
from django.db.models import Count
from multiservice.facade import Multiservice
from multiservice.facade.ttypes import *
from multiservice.types.ttypes import *
from lxml import etree
from thrift.transport import TSocket
from webapp.models import Category, Expression, Meaning, Segment, Source
PORT = 20000
HOST = 'multiservice.nlp.ipipan.waw.pl'
PROCESS_CHAIN = ['Concraft', 'Spejd', 'Nerf', 'MentionDetector']
class Command(BaseCommand):
help = 'Remove single expression meanings from database.'
def handle(self, *args, **options):
remove_meanings()
def remove_meanings(): # jeszcze tutaj pomijać wyrażenia pochodne, bo one tez sie wliczja jako expressions
meanings = Meaning.objects.filter(wikilink='').annotate(num_expr=Count('expressions'))
for meaning in meanings.filter(num_expr__lt=3):
if meaning.expressions.filter(main_expression=None).count() < 2:
print meaning