Entry.py 1.53 KB
#! /usr/bin/python
# -*- coding: utf-8 -*-

from importer.Syntax import Syntax
from importer.Meanings import Meanings
from importer.Semantics import Semantics
from connections.models import POS, Status
import connections.models

class Entry:

    def __init__(self, entry_tree, entry_meanings, meanings, frames):
        self._base = entry_tree._children[0]._children[0]._content
        self._pos = entry_tree._children[0]._children[1]._content
        self._status = entry_tree._children[1]._children[0]._children[0]._content
        print(self._base)
        self._syntax = Syntax.fromTree(entry_tree._children[2])
        if len(entry_tree._children) >= 7:
            self._meanings = Meanings.fromTree(entry_tree._children[5])
            self._semantics = Semantics.fromTree(self._base, self._pos, entry_tree._children[4], frames, self._meanings, self._syntax, entry_tree._children[6])
        else:
            self._meanings = None
            self._semantics = None
            
    def store(self, stored_positions):
        pos = POS.objects.get(tag=self._pos)
        status = Status.objects.get(key=self._status)
        # @TODO: nie ma frequency w xml-u
        entry = connections.models.Entry(name=self._base, pos=pos, status=status, frequency_1M=0, frequency_300M=0)
        entry.save()
        self._syntax.store(entry, stored_positions)
        if self._semantics is not None:
            self._semantics.store(entry, self._meanings)
        
    def __str__(self):
        return self._pos + '(' + self._base + ',' + str(self._syntax) + ').'