예제 #1
0
    def _doExtend(self, syms, s, t):
        """
        define a 1-branch grammar rule

        arguments:
            self  -
            syms  - grammar symbol table
            s     - left  part of rule
            t     - right part of rule

        returns:
            1-branch extending rule on success, otherwise None
        """

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

            if fs == None:  #
                lh = False
                rh = False
            else:  #
                rh = fs.positive.test(0)
                lh = fs.positive.test(1)
            if not symbolTable.featureConsistencyExtend(
                    fs, st.synf, None, lh, rh):
                print >> sys.stderr, '** bad syntactic feature inheritance'
                raise ellyException.FormatFailure
        except ellyException.FormatFailure:
            print >> sys.stderr, '** bad syntactic category or features'
            return None
        if ns >= symbolTable.NMAX or nt >= symbolTable.NMAX:
            print >> sys.stderr, 'too many syntactic categories'
            return None
        if ns < 0 or nt < 0:
            print >> sys.stderr, '** bad syntax specification'
            return None
        fs.negative.complement()
        ru = grammarRule.ExtendingRule(ns, fs.positive, fs.negative)
        #       print 'extd rule=' , unicode(ru)
        ru.gens = self.d1bp
        ru.utfet = ft.makeTest(
        )  # precombined positive and negative features for testing
        if s != '...' or t != '...':
            self.extens[nt].append(ru)  # add rule to grammar table
            self.mat.join(ns, nt)
            return ru
        else:
            print >> sys.stderr, '** bad type 0 rule'
            return None
예제 #2
0
    def _doExtend ( self , syms , s , t ):

        """
        define a 1-branch grammar rule

        arguments:
            self  -
            syms  - grammar symbol table
            s     - left  part of rule
            t     - right part of rule

        returns:
            1-branch extending rule on success, otherwise None
        """

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

            if fs == None: #
                lh = False
                rh = False
            else:            #
                rh = fs.positive.test(0)
                lh = fs.positive.test(1)
            if not symbolTable.featureConsistencyExtend(fs,st.synf,None,lh,rh):
                print >> sys.stderr , '** bad syntactic feature inheritance'
                raise ellyException.FormatFailure
        except ellyException.FormatFailure:
            print >> sys.stderr , '** bad syntactic category or features'
            return None
        if ns >= symbolTable.NMAX or nt >= symbolTable.NMAX:
            print >> sys.stderr , 'too many syntactic categories'
            return None
        if ns < 0 or nt < 0:
            print >> sys.stderr , '** bad syntax specification'
            return None
        fs.negative.complement()
        ru = grammarRule.ExtendingRule(ns,fs.positive,fs.negative)
#       print 'extd rule=' , unicode(ru)
        ru.gens = self.d1bp
        ru.utfet = ft.makeTest()       # precombined positive and negative features for testing
        if s != '...' or t != '...':
            self.extens[nt].append(ru) # add rule to grammar table
            self.mat.join(ns,nt)
            return ru
        else:
            print >> sys.stderr , '** bad type 0 rule'
            return None
예제 #3
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 ):
예제 #4
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