Пример #1
0
define cognitive semantics to compute plausibility scores for phrases
assigning positive or negative votes according to individual semantic
characteristics of phrases
"""

import ellyBits
import ellyChar
import ellyException
import semanticCommand
import featureSpecification
import symbolTable
import sys

_check = [ (lambda s : True)  ,
           (lambda s : symbolTable.featureConsistencyExtend(s.res,s.lft,s.rht,s.lh,s.rh)) ,
           (lambda s : symbolTable.featureConsistencySplit (s.res,s.lft,s.rht,s.lh,s.rh)) ]

class Status(object):
    """
    to group arguments for feature inheritance checking
    """
    def __init__ (self):
        self.res = None
        self.lft = None
        self.rht = None
        self.lh  = False
        self.rh  = False
        self.id  = None

def convertDefinition ( stb , inp , nwy ):
Пример #2
0
assigning positive or negative votes according to individual semantic
characteristics of phrases
"""

import ellyBits
import ellyChar
import ellyException
import semanticCommand
import featureSpecification
import symbolTable
import sys

_check = [(lambda s: True),
          (lambda s: symbolTable.featureConsistencyExtend(
              s.res, s.lft, s.rht, s.lh, s.rh)),
          (lambda s: symbolTable.featureConsistencySplit(
              s.res, s.lft, s.rht, s.lh, s.rh))]


class Status(object):
    """
    to group arguments for feature inheritance checking
    """
    def __init__(self):
        self.res = None
        self.lft = None
        self.rht = None
        self.lh = False
        self.rh = False
        self.id = None

Пример #3
0
    def _doSplit(self, syms, s, t, u):
        """
        define a 2-branch grammar rule

        arguments:
            self  -
            syms  - grammar symbol table
            s     - left  part of rule
            t     - first half of right part of rule
            u     - second

        returns:
            2-branch splitting rule on success, None otherwise
        """

        #       print 'split=' , s , '->' , t , u
        if t == None or len(t) == 0 or u == None or len(u) == 0:
            print >> sys.stderr, '** incomplete grammar rule'
            return None
        try:
            #           print 's=' , s
            ss = syntaxSpecification.SyntaxSpecification(syms, s)
            ns = ss.catg
            fs = ss.synf
            #           print 'fs=' , fs
            st = syntaxSpecification.SyntaxSpecification(syms, t)
            nt = st.catg
            ft = st.synf
            su = syntaxSpecification.SyntaxSpecification(syms, u)
            nu = su.catg
            fu = su.synf

            if fs == None:  #
                lh = False
                rh = False
            else:  #
                rh = fs.positive.test(0)
                lh = fs.positive.test(1)
            if not symbolTable.featureConsistencySplit(fs, ft, fu, lh, rh):
                print >> sys.stderr, '** bad syntactic feature inheritance'
                raise ellyException.FormatFailure
        except ellyException.FormatFailure:
            return None
        if ns >= symbolTable.NMAX or nt >= symbolTable.NMAX or nu >= symbolTable.NMAX:
            print >> sys.stderr, 'too many syntactic categories'
            return None
        if ns < 0 or nt < 0 or nu < 0:
            print >> sys.stderr, '** bad syntax specification'
            return None
        fs.negative.complement()
        ru = grammarRule.SplittingRule(ns, fs.positive, fs.negative)
        #       print 'splt rule=' , unicode(ru)
        ru.gens = self.d2bp
        ru.ltfet = ft.makeTest(
        )  # combine positive and negative features for testing
        ru.rtfet = fu.makeTest(
        )  # combine positive and negative features for testing
        ru.rtyp = nu
        if t == '...':
            if u == '...':
                print >> sys.stderr, '** bad type 0 rule'
                return None  # cannot have a rule of the form X->... ...
            else:
                self.mat.join(ns, nu)  # for rule of form X->... Y, we see X->Y
        else:
            self.mat.join(ns, nt)  # otherwise, treat as normal 2-branch
        self.splits[nt].append(ru)  # add rule to grammar table
        return ru
Пример #4
0
    def _doSplit ( self , syms , s, t, u ):

        """
        define a 2-branch grammar rule

        arguments:
            self  -
            syms  - grammar symbol table
            s     - left  part of rule
            t     - first half of right part of rule
            u     - second

        returns:
            2-branch splitting rule on success, None otherwise
        """

#       print 'split=' , s , '->' , t , u
        if t == None or len(t) == 0 or u == None or len(u) == 0:
            print >> sys.stderr , '** incomplete grammar rule'
            return None
        try:
#           print 's=' , s
            ss = syntaxSpecification.SyntaxSpecification(syms,s)
            ns = ss.catg
            fs = ss.synf
#           print 'fs=' , fs
            st = syntaxSpecification.SyntaxSpecification(syms,t)
            nt = st.catg
            ft = st.synf
            su = syntaxSpecification.SyntaxSpecification(syms,u)
            nu = su.catg
            fu = su.synf

            if fs == None: #
                lh = False
                rh = False
            else:            #
                rh = fs.positive.test(0)
                lh = fs.positive.test(1)
            if not symbolTable.featureConsistencySplit(fs,ft,fu,lh,rh):
                print >> sys.stderr , '** bad syntactic feature inheritance'
                raise ellyException.FormatFailure
        except ellyException.FormatFailure:
            return None
        if ns >= symbolTable.NMAX or nt >= symbolTable.NMAX or nu >= symbolTable.NMAX:
            print >> sys.stderr , 'too many syntactic categories'
            return None
        if ns < 0 or nt < 0 or nu < 0:
            print >> sys.stderr , '** bad syntax specification'
            return None
        fs.negative.complement()
        ru = grammarRule.SplittingRule(ns,fs.positive,fs.negative)
#       print 'splt rule=' , unicode(ru)
        ru.gens = self.d2bp
        ru.ltfet = ft.makeTest()       # combine positive and negative features for testing
        ru.rtfet = fu.makeTest()       # combine positive and negative features for testing
        ru.rtyp  = nu
        if t == '...':
            if u == '...':
                print >> sys.stderr , '** bad type 0 rule'
                return None            # cannot have a rule of the form X->... ...
            else:
                self.mat.join(ns,nu)   # for rule of form X->... Y, we see X->Y
        else:
            self.mat.join(ns,nt)       # otherwise, treat as normal 2-branch
        self.splits[nt].append(ru)     # add rule to grammar table
        return ru