How to use the cython.combinator.Combinator function in Cython

To help you get started, we’ve selected a few Cython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github masashi-y / depccg / cython / combinator.py View on Github external
return False

    def head_is_left(self, left, right):
        return not ( left.is_modifier or left.is_type_raised )

    def apply(self, left, right):
        if left.is_modifier:
            return right
        res = cat.make(cat.make(
                        left.left, self.result_slash, right.left.right),
                        right.slash, right.right)
        return Combinator.correct_wildcard_features(
                res, right.left.left, left.right)


class GeneralizedBackwardComposition(Combinator):
    # (Y|Z_1)|Z_2 X\Y --> (X|Z_1)|Z_2
    def __init__(self, left, right, slash):
        super(GeneralizedBackwardComposition, self).__init__(RuleType.GBX)
        self.left_slash = left
        self.right_slash = right
        self.result_slash = slash

    def __str__(self):
        return "
github masashi-y / depccg / cython / combinator.py View on Github external
res.append((rule,
                    rule.apply(left, right),
                    rule.head_is_left(left, right)))
        return res

    def __str__(self):
        return "<*>"

class UnaryRule(Combinator):
    def __init__(self):
        super(UnaryRule, self).__init__(RuleType.UNARY)

    def __str__(self):
        return ""

class Conjunction(Combinator):
    # A   ,   B  and  C
    # NP CONJ NP CONJ NP
    #            -----(Conj)
    #            NP\NP
    #         --------<
    #            NP
    #     ------------(Conj)
    #        NP\NP
    # ----------------<
    #         NP
    def __init__(self):
        super(Conjunction, self).__init__(RuleType.CONJ)

    def __str__(self):
        return "<Φ>"
github masashi-y / depccg / cython / combinator.py View on Github external
super(RemovePunctuationLeft, self).__init__(RuleType.LP)

    def __str__(self):
        return "<rp>"

    def can_apply(self, left, right):
        return left == cat.LQU or left == cat.LRB

    def head_is_left(self, left, right):
        return False

    def apply(self, left, right):
        return right


class SpecialCombinator(Combinator):
    def __init__(self, left, right, result, head_is_left):
        super(SpecialCombinator, self).__init__(RuleType.NOISE)
        self.left = left
        self.right = right
        self.result = result
        self.head_is_left = head_is_left

    def __str__(self):
        return ""

    def can_apply(self, left, right):
        return self.left.matches(left) and \
                self.right.matches(right)

    def head_is_left(self, left, right):
        return self.head_is_left</rp>
github masashi-y / depccg / cython / combinator.py View on Github external
return "<rp>"

    def can_apply(self, left, right):
        # Disallow punctuation combining with nouns,
        # to avoid getting NPs like Barack Obama .
        return left.is_punct if self.punct_is_left else \
                right.is_punct and not cat.N.matches(left)

    def head_is_left(self, left, right):
        return not self.punct_is_left

    def apply(self, left, right):
        return right if self.punct_is_left else left


class RemovePunctuationLeft(Combinator):
    # Open Brackets and Quotation
    def __init__(self):
        super(RemovePunctuationLeft, self).__init__(RuleType.LP)

    def __str__(self):
        return "<rp>"

    def can_apply(self, left, right):
        return left == cat.LQU or left == cat.LRB

    def head_is_left(self, left, right):
        return False

    def apply(self, left, right):
        return right
</rp></rp>
github masashi-y / depccg / cython / combinator.py View on Github external
def apply(self, left, right):
        if right.is_modifier:
            return left
        res = cat.make(cat.make(
                    right.left, self.result_slash, left.left.right),
                left.slash, left.right)
        return Combinator.correct_wildcard_features(
                res, left.left.left, right.right)
github masashi-y / depccg / cython / combinator.py View on Github external
return (left == cat.CONJ or \
                left == cat.COMMA or \
                left == cat.SEMICOLON) and \
                not right.is_punct and \
                not right.is_type_raised and \
                not (not right.is_functor and right.type == "N")


    def head_is_left(self, left, right):
        return False

    def apply(self, left, right):
        return cat.make(right, Slash.Bwd(), right)


class RemovePunctuation(Combinator):
    def __init__(self, punct_is_left):
        super(RemovePunctuation, self).__init__(RuleType.RP)
        self.punct_is_left = punct_is_left

    def __str__(self):
        return "<rp>"

    def can_apply(self, left, right):
        # Disallow punctuation combining with nouns,
        # to avoid getting NPs like Barack Obama .
        return left.is_punct if self.punct_is_left else \
                right.is_punct and not cat.N.matches(left)

    def head_is_left(self, left, right):
        return not self.punct_is_left
</rp>
github masashi-y / depccg / cython / combinator.py View on Github external
def can_apply(self, left, right):
        return right.is_functor and \
                right.slash == Slash.Bwd() and \
                right.right.matches(left)

    def head_is_left(self, left, right):
        return right.is_modifier or right.is_type_raised

    def apply(self, left, right):
        res = right.left
        return Combinator.correct_wildcard_features(
                res, right.right, left)


class ForwardComposition(Combinator):
    # S/NP NP/(S/NP) --> S/(S/NP)
    def __init__(self, left, right, slash):
        super(ForwardComposition, self).__init__(RuleType.FC)
        self.left_slash = left
        self.right_slash = right
        self.result_slash = slash

    def __str__(self):
        return ">B"

    def can_apply(self, left, right):
        return left.is_functor and \
                right.is_functor and \
                left.right.matches(right.left) and \
                left.slash == self.left_slash and \
                right.slash == self.right_slash
github masashi-y / depccg / cython / combinator.py View on Github external
right.right.matches(left.left) and \
                left.slash == self.left_slash and \
                right.slash == self.right_slash and \
                not left.left.is_N_or_NP # Additional constraint from Steedman (2000)

    def head_is_left(self, left, right):
        return right.is_modifier or right.is_type_raised

    def apply(self, left, right):
        res = left if right.is_modifier else \
                    cat.make(right.left, self.result_slash, left.right)
        return Combinator.correct_wildcard_features(
                res, left.left, right.right)


class GeneralizedForwardComposition(Combinator):
    # X/Y (Y|Z_1)|Z_2 --> (X|Z_1)|Z_2
    def __init__(self, left, right, slash):
        super(GeneralizedForwardComposition, self).__init__(RuleType.GFC)
        self.left_slash = left
        self.right_slash = right
        self.result_slash = slash

    def __str__(self):
        return ">Bx"

    def can_apply(self, left, right):
        if left.is_functor and \
            right.is_functor and \
            right.left.is_functor:
                return left.right.matches(right.left.left) and \
                        left.slash == self.left_slash and \
github masashi-y / depccg / cython / combinator.py View on Github external
def __str__(self):
        return ""

    def can_apply(self, left, right):
        return self.left.matches(left) and \
                self.right.matches(right)

    def head_is_left(self, left, right):
        return self.head_is_left

    def apply(self, left, right):
        return self.result


class ForwardApplication(Combinator):
    def __init__(self):
        super(ForwardApplication, self).__init__(RuleType.FA)

    def __str__(self):
        return "&gt;"

    def can_apply(self, left, right):
        return left.is_functor and \
                left.slash == Slash.Fwd() and \
                left.right.matches(right)

    def head_is_left(self, left, right):
        return not ( left.is_modifier or left.is_type_raised )

    def apply(self, left, right):
        if left.is_modifier:
github masashi-y / depccg / cython / combinator.py View on Github external
right.is_functor and \
                left.right.matches(right.left) and \
                left.slash == self.left_slash and \
                right.slash == self.right_slash

    def head_is_left(self, left, right):
        return not ( left.is_modifier or left.is_type_raised )

    def apply(self, left, right):
        res = right if left.is_modifier else \
                cat.make(left.left, self.result_slash, right.right)
        return Combinator.correct_wildcard_features(
                res, right.left, left.right)


class BackwardComposition(Combinator):
    # NP\(S/NP) S\NP --&gt; S\(S/NP)
    def __init__(self, left, right, slash):
        super(BackwardComposition, self).__init__(RuleType.BX)
        self.left_slash = left
        self.right_slash = right
        self.result_slash = slash

    def __str__(self):
        return "