コード例 #1
0
    def generate_cfg(self, grammar, head):
        symbol = head or Symbol(self.__class__.__name__)
        compatible = []

        for _, other_cls in grammar.namespace.items():
            if other_cls in self.exceptions:
                continue

            if hasattr(other_cls, "__name__") and other_cls.__name__ in self.exceptions:
                continue

            if self.interface.is_compatible(other_cls):
                compatible.append(other_cls)

        if not compatible:
            raise ValueError(
                "Cannot find compatible implementations for <class %s>" % self.interface
            )

        return Subset(symbol.name, *compatible).generate_cfg(grammar, symbol)
コード例 #2
0
 def __init__(self, features: Subset("Subset", "Hello", "World", 1)):
     pass
コード例 #3
0
 def __init__(self, features: Subset("Subset", DiscreteValue(1, 5),
                                     "Hello", 1, None)):
     self.features = features
コード例 #4
0
 def __init__(
     self,
     features: Subset("Subset", DiscreteValue(1, 5),
                      CategoricalValue("adam", "sgd")),
 ):
     pass
コード例 #5
0
 def __init__(self, features: Subset('Subset', Discrete(1, 5), 'Hello',
                                     1, None)):
     self.features = features
コード例 #6
0
 def __init__(self, features: Subset('Subset', Discrete(1, 5),
                                     Categorical('adam', 'sgd'))):
     pass
コード例 #7
0
 def __init__(self, xs: Subset("xs", A, D)):
     self.xs = xs