本文整理匯總了Python中nltk.chunk.RegexpParser方法的典型用法代碼示例。如果您正苦於以下問題:Python chunk.RegexpParser方法的具體用法?Python chunk.RegexpParser怎麽用?Python chunk.RegexpParser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nltk.chunk
的用法示例。
在下文中一共展示了chunk.RegexpParser方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _chunk_parse
# 需要導入模塊: from nltk import chunk [as 別名]
# 或者: from nltk.chunk import RegexpParser [as 別名]
def _chunk_parse(self, grammar=None, root_label='record', trace=0, **kwargs):
"""
Returns an element tree structure corresponding to a toolbox data file
parsed according to the chunk grammar.
:type grammar: str
:param grammar: Contains the chunking rules used to parse the
database. See ``chunk.RegExp`` for documentation.
:type root_label: str
:param root_label: The node value that should be used for the
top node of the chunk structure.
:type trace: int
:param trace: The level of tracing that should be used when
parsing a text. ``0`` will generate no tracing output;
``1`` will generate normal tracing output; and ``2`` or
higher will generate verbose tracing output.
:type kwargs: dict
:param kwargs: Keyword arguments passed to ``toolbox.StandardFormat.fields()``
:rtype: ElementTree._ElementInterface
"""
from nltk import chunk
from nltk.tree import Tree
cp = chunk.RegexpParser(grammar, root_label=root_label, trace=trace)
db = self.parse(**kwargs)
tb_etree = Element('toolbox_data')
header = db.find('header')
tb_etree.append(header)
for record in db.findall('record'):
parsed = cp.parse([(elem.text, elem.tag) for elem in record])
tb_etree.append(self._tree2etree(parsed))
return tb_etree
示例2: _chunk_parse
# 需要導入模塊: from nltk import chunk [as 別名]
# 或者: from nltk.chunk import RegexpParser [as 別名]
def _chunk_parse(self, grammar=None, top_node='record', trace=0, **kwargs):
"""
Returns an element tree structure corresponding to a toolbox data file
parsed according to the chunk grammar.
:type grammar: str
:param grammar: Contains the chunking rules used to parse the
database. See ``chunk.RegExp`` for documentation.
:type top_node: str
:param top_node: The node value that should be used for the
top node of the chunk structure.
:type trace: int
:param trace: The level of tracing that should be used when
parsing a text. ``0`` will generate no tracing output;
``1`` will generate normal tracing output; and ``2`` or
higher will generate verbose tracing output.
:type kwargs: dict
:param kwargs: Keyword arguments passed to ``toolbox.StandardFormat.fields()``
:rtype: ElementTree._ElementInterface
"""
from nltk import chunk
from nltk.tree import Tree
cp = chunk.RegexpParser(grammar, top_node=top_node, trace=trace)
db = self.parse(**kwargs)
tb_etree = Element('toolbox_data')
header = db.find('header')
tb_etree.append(header)
for record in db.findall('record'):
parsed = cp.parse([(elem.text, elem.tag) for elem in record])
tb_etree.append(self._tree2etree(parsed))
return tb_etree
示例3: initialize
# 需要導入模塊: from nltk import chunk [as 別名]
# 或者: from nltk.chunk import RegexpParser [as 別名]
def initialize(self, resources: Resources, configs: Config):
super().initialize(resources, configs)
self.chunker = RegexpParser(configs.pattern)
示例4: __str__
# 需要導入模塊: from nltk import chunk [as 別名]
# 或者: from nltk.chunk import RegexpParser [as 別名]
def __str__(self):
"""
:return: a verbose string representation of this
``RegexpParser``.
:rtype: str
"""
s = "chunk.RegexpParser with %d stages:\n" % len(self._stages)
margin = 0
for parser in self._stages:
s += "%s\n" % parser
return s[:-1]
##//////////////////////////////////////////////////////
## Demonstration code
##//////////////////////////////////////////////////////
示例5: __repr__
# 需要導入模塊: from nltk import chunk [as 別名]
# 或者: from nltk.chunk import RegexpParser [as 別名]
def __repr__(self):
"""
:return: a concise string representation of this ``chunk.RegexpParser``.
:rtype: str
"""
return "<chunk.RegexpParser with %d stages>" % len(self._stages)
示例6: __str__
# 需要導入模塊: from nltk import chunk [as 別名]
# 或者: from nltk.chunk import RegexpParser [as 別名]
def __str__(self):
"""
:return: a verbose string representation of this
``RegexpParser``.
:rtype: str
"""
s = "chunk.RegexpParser with %d stages:\n" % len(self._stages)
margin = 0
for parser in self._stages:
s += "%s\n" % parser
return s[:-1]
##//////////////////////////////////////////////////////
## Demonstration code
##//////////////////////////////////////////////////////
示例7: __str__
# 需要導入模塊: from nltk import chunk [as 別名]
# 或者: from nltk.chunk import RegexpParser [as 別名]
def __str__(self):
"""
:return: a verbose string representation of this
``RegexpParser``.
:rtype: str
"""
s = "chunk.RegexpParser with %d stages:\n" % len(self._stages)
margin = 0
for parser in self._stages:
s += parser.__str__() + "\n"
return s[:-1]
##//////////////////////////////////////////////////////
## Demonstration code
##//////////////////////////////////////////////////////