def nonterminals(symbols):
"""
Given a string containing a list of symbol names, return a list of
``Nonterminals`` constructed from those symbols.
:param symbols: The symbol name string. This string can be
delimited by either spaces or commas.
:type symbols: str
:return: A list of ``Nonterminals`` constructed from the symbol
names given in ``symbols``. The ``Nonterminals`` are sorted
in the same order as the symbols names.
:rtype: list(Nonterminal)
"""
if ',' in symbols: symbol_list = symbols.split(',')
else: symbol_list = symbols.split()
return [Nonterminal(s.strip()) for s in symbol_list]
python类nonterminals()的实例源码
grammar.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def nonterminals(symbols):
"""
Given a string containing a list of symbol names, return a list of
``Nonterminals`` constructed from those symbols.
:param symbols: The symbol name string. This string can be
delimited by either spaces or commas.
:type symbols: str
:return: A list of ``Nonterminals`` constructed from the symbol
names given in ``symbols``. The ``Nonterminals`` are sorted
in the same order as the symbols names.
:rtype: list(Nonterminal)
"""
if ',' in symbols: symbol_list = symbols.split(',')
else: symbol_list = symbols.split()
return [Nonterminal(s.strip()) for s in symbol_list]
def nonterminals(symbols):
"""
Given a string containing a list of symbol names, return a list of
``Nonterminals`` constructed from those symbols.
:param symbols: The symbol name string. This string can be
delimited by either spaces or commas.
:type symbols: str
:return: A list of ``Nonterminals`` constructed from the symbol
names given in ``symbols``. The ``Nonterminals`` are sorted
in the same order as the symbols names.
:rtype: list(Nonterminal)
"""
if ',' in symbols: symbol_list = symbols.split(',')
else: symbol_list = symbols.split()
return [Nonterminal(s.strip()) for s in symbol_list]
def nonterminals(symbols):
"""
Given a string containing a list of symbol names, return a list of
``Nonterminals`` constructed from those symbols.
:param symbols: The symbol name string. This string can be
delimited by either spaces or commas.
:type symbols: str
:return: A list of ``Nonterminals`` constructed from the symbol
names given in ``symbols``. The ``Nonterminals`` are sorted
in the same order as the symbols names.
:rtype: list(Nonterminal)
"""
if ',' in symbols: symbol_list = symbols.split(',')
else: symbol_list = symbols.split()
return [Nonterminal(s.strip()) for s in symbol_list]
def nonterminals(symbols):
"""
Given a string containing a list of symbol names, return a list of
``Nonterminals`` constructed from those symbols.
:param symbols: The symbol name string. This string can be
delimited by either spaces or commas.
:type symbols: str
:return: A list of ``Nonterminals`` constructed from the symbol
names given in ``symbols``. The ``Nonterminals`` are sorted
in the same order as the symbols names.
:rtype: list(Nonterminal)
"""
if ',' in symbols: symbol_list = symbols.split(',')
else: symbol_list = symbols.split()
return [Nonterminal(s.strip()) for s in symbol_list]
def nonterminals(symbols):
"""
Given a string containing a list of symbol names, return a list of
``Nonterminals`` constructed from those symbols.
:param symbols: The symbol name string. This string can be
delimited by either spaces or commas.
:type symbols: str
:return: A list of ``Nonterminals`` constructed from the symbol
names given in ``symbols``. The ``Nonterminals`` are sorted
in the same order as the symbols names.
:rtype: list(Nonterminal)
"""
if ',' in symbols: symbol_list = symbols.split(',')
else: symbol_list = symbols.split()
return [Nonterminal(s.strip()) for s in symbol_list]
def nonterminals(symbols):
"""
Given a string containing a list of symbol names, return a list of
``Nonterminals`` constructed from those symbols.
:param symbols: The symbol name string. This string can be
delimited by either spaces or commas.
:type symbols: str
:return: A list of ``Nonterminals`` constructed from the symbol
names given in ``symbols``. The ``Nonterminals`` are sorted
in the same order as the symbols names.
:rtype: list(Nonterminal)
"""
if ',' in symbols: symbol_list = symbols.split(',')
else: symbol_list = symbols.split()
return [Nonterminal(s.strip()) for s in symbol_list]
def nonterminals(symbols):
"""
Given a string containing a list of symbol names, return a list of
``Nonterminals`` constructed from those symbols.
:param symbols: The symbol name string. This string can be
delimited by either spaces or commas.
:type symbols: str
:return: A list of ``Nonterminals`` constructed from the symbol
names given in ``symbols``. The ``Nonterminals`` are sorted
in the same order as the symbols names.
:rtype: list(Nonterminal)
"""
if ',' in symbols: symbol_list = symbols.split(',')
else: symbol_list = symbols.split()
return [Nonterminal(s.strip()) for s in symbol_list]
def leftcorners(self, cat):
"""
Return the set of all nonterminals that the given nonterminal
can start with, including itself.
This is the reflexive, transitive closure of the immediate
leftcorner relation: (A > B) iff (A -> B beta)
:param cat: the parent of the leftcorners
:type cat: Nonterminal
:return: the set of all leftcorners
:rtype: set(Nonterminal)
"""
return self._leftcorners.get(cat, set([cat]))
def leftcorner_parents(self, cat):
"""
Return the set of all nonterminals for which the given category
is a left corner. This is the inverse of the leftcorner relation.
:param cat: the suggested leftcorner
:type cat: Nonterminal
:return: the set of all parents to the leftcorner
:rtype: set(Nonterminal)
"""
return self._leftcorner_parents.get(cat, set([cat]))
def __init__(self, start, productions):
"""
Create a new feature-based grammar, from the given start
state and set of ``Productions``.
:param start: The start symbol
:type start: FeatStructNonterminal
:param productions: The list of productions that defines the grammar
:type productions: list(Production)
"""
CFG.__init__(self, start, productions)
# The difference with CFG is that the productions are
# indexed on the TYPE feature of the nonterminals.
# This is calculated by the method _get_type_if_possible().
grammar.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 39
收藏 0
点赞 0
评论 0
def leftcorners(self, cat):
"""
Return the set of all nonterminals that the given nonterminal
can start with, including itself.
This is the reflexive, transitive closure of the immediate
leftcorner relation: (A > B) iff (A -> B beta)
:param cat: the parent of the leftcorners
:type cat: Nonterminal
:return: the set of all leftcorners
:rtype: set(Nonterminal)
"""
return self._leftcorners.get(cat, set([cat]))
grammar.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 29
收藏 0
点赞 0
评论 0
def leftcorner_parents(self, cat):
"""
Return the set of all nonterminals for which the given category
is a left corner. This is the inverse of the leftcorner relation.
:param cat: the suggested leftcorner
:type cat: Nonterminal
:return: the set of all parents to the leftcorner
:rtype: set(Nonterminal)
"""
return self._leftcorner_parents.get(cat, set([cat]))
grammar.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def __init__(self, start, productions):
"""
Create a new feature-based grammar, from the given start
state and set of ``Productions``.
:param start: The start symbol
:type start: FeatStructNonterminal
:param productions: The list of productions that defines the grammar
:type productions: list(Production)
"""
CFG.__init__(self, start, productions)
# The difference with CFG is that the productions are
# indexed on the TYPE feature of the nonterminals.
# This is calculated by the method _get_type_if_possible().
def leftcorners(self, cat):
"""
Return the set of all nonterminals that the given nonterminal
can start with, including itself.
This is the reflexive, transitive closure of the immediate
leftcorner relation: (A > B) iff (A -> B beta)
:param cat: the parent of the leftcorners
:type cat: Nonterminal
:return: the set of all leftcorners
:rtype: set(Nonterminal)
"""
return self._leftcorners.get(cat, set([cat]))
def leftcorner_parents(self, cat):
"""
Return the set of all nonterminals for which the given category
is a left corner. This is the inverse of the leftcorner relation.
:param cat: the suggested leftcorner
:type cat: Nonterminal
:return: the set of all parents to the leftcorner
:rtype: set(Nonterminal)
"""
return self._leftcorner_parents.get(cat, set([cat]))
def __init__(self, start, productions):
"""
Create a new feature-based grammar, from the given start
state and set of ``Productions``.
:param start: The start symbol
:type start: FeatStructNonterminal
:param productions: The list of productions that defines the grammar
:type productions: list(Production)
"""
CFG.__init__(self, start, productions)
# The difference with CFG is that the productions are
# indexed on the TYPE feature of the nonterminals.
# This is calculated by the method _get_type_if_possible().
def leftcorners(self, cat):
"""
Return the set of all nonterminals that the given nonterminal
can start with, including itself.
This is the reflexive, transitive closure of the immediate
leftcorner relation: (A > B) iff (A -> B beta)
:param cat: the parent of the leftcorners
:type cat: Nonterminal
:return: the set of all leftcorners
:rtype: set(Nonterminal)
"""
return self._leftcorners.get(cat, set([cat]))
def leftcorner_parents(self, cat):
"""
Return the set of all nonterminals for which the given category
is a left corner. This is the inverse of the leftcorner relation.
:param cat: the suggested leftcorner
:type cat: Nonterminal
:return: the set of all parents to the leftcorner
:rtype: set(Nonterminal)
"""
return self._leftcorner_parents.get(cat, set([cat]))
def __init__(self, start, productions):
"""
Create a new feature-based grammar, from the given start
state and set of ``Productions``.
:param start: The start symbol
:type start: FeatStructNonterminal
:param productions: The list of productions that defines the grammar
:type productions: list(Production)
"""
CFG.__init__(self, start, productions)
# The difference with CFG is that the productions are
# indexed on the TYPE feature of the nonterminals.
# This is calculated by the method _get_type_if_possible().
def leftcorners(self, cat):
"""
Return the set of all nonterminals that the given nonterminal
can start with, including itself.
This is the reflexive, transitive closure of the immediate
leftcorner relation: (A > B) iff (A -> B beta)
:param cat: the parent of the leftcorners
:type cat: Nonterminal
:return: the set of all leftcorners
:rtype: set(Nonterminal)
"""
return self._leftcorners.get(cat, set([cat]))
def leftcorner_parents(self, cat):
"""
Return the set of all nonterminals for which the given category
is a left corner. This is the inverse of the leftcorner relation.
:param cat: the suggested leftcorner
:type cat: Nonterminal
:return: the set of all parents to the leftcorner
:rtype: set(Nonterminal)
"""
return self._leftcorner_parents.get(cat, set([cat]))
def __init__(self, start, productions):
"""
Create a new feature-based grammar, from the given start
state and set of ``Productions``.
:param start: The start symbol
:type start: FeatStructNonterminal
:param productions: The list of productions that defines the grammar
:type productions: list(Production)
"""
CFG.__init__(self, start, productions)
# The difference with CFG is that the productions are
# indexed on the TYPE feature of the nonterminals.
# This is calculated by the method _get_type_if_possible().
def leftcorners(self, cat):
"""
Return the set of all nonterminals that the given nonterminal
can start with, including itself.
This is the reflexive, transitive closure of the immediate
leftcorner relation: (A > B) iff (A -> B beta)
:param cat: the parent of the leftcorners
:type cat: Nonterminal
:return: the set of all leftcorners
:rtype: set(Nonterminal)
"""
return self._leftcorners.get(cat, set([cat]))
def leftcorner_parents(self, cat):
"""
Return the set of all nonterminals for which the given category
is a left corner. This is the inverse of the leftcorner relation.
:param cat: the suggested leftcorner
:type cat: Nonterminal
:return: the set of all parents to the leftcorner
:rtype: set(Nonterminal)
"""
return self._leftcorner_parents.get(cat, set([cat]))
def __init__(self, start, productions):
"""
Create a new feature-based grammar, from the given start
state and set of ``Productions``.
:param start: The start symbol
:type start: FeatStructNonterminal
:param productions: The list of productions that defines the grammar
:type productions: list(Production)
"""
CFG.__init__(self, start, productions)
# The difference with CFG is that the productions are
# indexed on the TYPE feature of the nonterminals.
# This is calculated by the method _get_type_if_possible().
def leftcorners(self, cat):
"""
Return the set of all nonterminals that the given nonterminal
can start with, including itself.
This is the reflexive, transitive closure of the immediate
leftcorner relation: (A > B) iff (A -> B beta)
:param cat: the parent of the leftcorners
:type cat: Nonterminal
:return: the set of all leftcorners
:rtype: set(Nonterminal)
"""
return self._leftcorners.get(cat, set([cat]))
def leftcorner_parents(self, cat):
"""
Return the set of all nonterminals for which the given category
is a left corner. This is the inverse of the leftcorner relation.
:param cat: the suggested leftcorner
:type cat: Nonterminal
:return: the set of all parents to the leftcorner
:rtype: set(Nonterminal)
"""
return self._leftcorner_parents.get(cat, set([cat]))
def __init__(self, start, productions):
"""
Create a new feature-based grammar, from the given start
state and set of ``Productions``.
:param start: The start symbol
:type start: FeatStructNonterminal
:param productions: The list of productions that defines the grammar
:type productions: list(Production)
"""
CFG.__init__(self, start, productions)
# The difference with CFG is that the productions are
# indexed on the TYPE feature of the nonterminals.
# This is calculated by the method _get_type_if_possible().
def leftcorners(self, cat):
"""
Return the set of all nonterminals that the given nonterminal
can start with, including itself.
This is the reflexive, transitive closure of the immediate
leftcorner relation: (A > B) iff (A -> B beta)
:param cat: the parent of the leftcorners
:type cat: Nonterminal
:return: the set of all leftcorners
:rtype: set(Nonterminal)
"""
return self._leftcorners.get(cat, set([cat]))