nlp :: NLPSentence
Document
.nlp :: NLPSentence :: defaultinit
nlp :: NLPSentence :: index=
Index of this sentence in the input text.nlp $ NLPSentence :: SELF
Type of this instance, automatically specialized in every classcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nlp :: NLPSentence :: defaultinit
core :: Object :: defaultinit
nlp :: NLPSentence :: index=
Index of this sentence in the input text.core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# Represent one sentence in a `Document`.
class NLPSentence
# Index of this sentence in the input text.
var index: Int
# NLPTokens contained in `self`.
var tokens = new Array[NLPToken]
# Init `self` from an XML element.
#
# ~~~
# var xml = """
# <sentence id="1">
# <tokens>
# <token id="1">
# <word>Stanford</word>
# <lemma>Stanford</lemma>
# <CharacterOffsetBegin>0</CharacterOffsetBegin>
# <CharacterOffsetEnd>8</CharacterOffsetEnd>
# <POS>NNP</POS>
# </token>
# <token id="2">
# <word>University</word>
# <lemma>University</lemma>
# <CharacterOffsetBegin>9</CharacterOffsetBegin>
# <CharacterOffsetEnd>19</CharacterOffsetEnd>
# <POS>NNP</POS>
# </token>
# </tokens>
# </sentence>""".to_xml["sentence"].first.as(XMLStartTag)
#
# var sentence = new NLPSentence.from_xml(xml)
# assert sentence.index == 1
# assert sentence.tokens.length == 2
# ~~~
init from_xml(xml: XMLStartTag) do
var index = xml.attributes.first.as(XMLStringAttr).value.to_i
for obj in xml["tokens"].first["token"] do
if obj isa XMLStartTag then
tokens.add new NLPToken.from_xml(obj)
else
print "Warning: malformed xml, `tokens` is supposed to contain `token` tags"
end
end
init(index)
end
end
lib/nlp/stanford.nit:190,1--237,3