容器

跨度

class

Doc对象中截取的一段。

Span.__init__ 方法

从切片 doc[start : end] 创建一个 Span 对象。

名称描述
docThe parent document. Doc
startThe index of the first token of the span. int
endThe index of the first token after the span. int
labelA label to attach to the span, e.g. for named entities. Union[str, int]
vectorA meaning representation of the span. numpy.ndarray[ndim=1, dtype=float32]
vector_normThe L2 norm of the document’s vector representation. float
kb_idA knowledge base ID to attach to the span, e.g. for named entities. Union[str, int]
span_idAn ID to associate with the span. Union[str, int]

Span.__getitem__ 方法

获取一个Token对象。

名称描述
iThe index of the token within the span. int

获取一个Span对象。

名称描述
start_endThe slice of the span to get. Tuple[int, int]

Span.__iter__ 方法

遍历Token对象。

名称描述

Span.__len__ 方法

获取该span中的token数量。

名称描述

Span.set_extension 类方法

Span上定义一个自定义属性,该属性可通过Span._访问。 详情请参阅关于 custom attributes的文档。

名称描述
nameName of the attribute to set by the extension. For example, "my_attr" will be available as span._.my_attr. str
defaultOptional default value of the attribute if no getter or method is defined. Optional[Any]
methodSet a custom method on the object, for example span._.compare(other_span). Optional[Callable[[Span,], Any]]
getterGetter function that takes the object and returns an attribute value. Is called when the user accesses the ._ attribute. Optional[Callable[[Span], Any]]
setterSetter function that takes the Span and a value, and modifies the object. Is called when the user writes to the Span._ attribute. Optional[Callable[[Span, Any], None]]
forceForce overwriting existing attribute. bool

Span.get_extension 类方法

通过名称查找先前注册的扩展。如果扩展已注册,则返回一个4元组(default, method, getter, setter)。否则抛出KeyError

名称描述
nameName of the extension. str

Span.has_extension 类方法

检查扩展是否已在Span类上注册。

名称描述
nameName of the extension to check. str

Span.remove_extension 类方法

移除之前注册的扩展。

名称描述
nameName of the extension. str

Span.char_span 方法

从切片 span.text[start:end] 创建一个 Span 对象。如果字符索引未映射到有效范围,则返回 None

名称描述
startThe index of the first character of the span. int
endThe index of the last character after the span. int
labelA label to attach to the span, e.g. for named entities. Union[int, str]
kb_idAn ID from a knowledge base to capture the meaning of a named entity. Union[int, str]
vectorA meaning representation of the span. numpy.ndarray[ndim=1, dtype=float32]
idUnused. Union[int, str]
alignment_mode v3.5.1How character indices snap to token boundaries. Options: "strict" (no snapping), "contract" (span of all tokens completely within the character span), "expand" (span of all tokens at least partially covered by the character span). Defaults to "strict". str
span_id v3.5.1An identifier to associate with the span. Union[int, str]

Span.similarity 方法需要模型

进行语义相似度估算。默认估算方法是使用词向量平均值的余弦相似度。

名称描述
otherThe object to compare with. By default, accepts Doc, Span, Token and Lexeme objects. Union[Doc,Span,Token,Lexeme]

Span.get_lca_matrix 方法

计算给定Span的最低公共祖先矩阵。返回包含祖先整数索引的LCA矩阵,如果未找到公共祖先(例如当span排除了必要祖先时)则返回-1

名称描述

Span.to_array 方法

给定一个包含M个属性ID的列表,将这些标记导出为一个形状为(N, M)的numpy ndarray数组,其中N是文档的长度。这些值将是32位整数。

名称描述
attr_idsA list of attributes (int IDs or string names) or a single attribute (int ID or string name). Union[int, str, List[Union[int, str]]]

Span.ents 属性需要模型

完全位于该范围内的命名实体。返回一个由Span对象组成的元组。

名称描述

Span.noun_chunks 属性需要模型

遍历该范围内的基本名词短语。如果文档已经过句法分析,则生成基本名词短语Span对象。基本名词短语或称"NP块",是指不允许其他NP嵌套其中的名词短语——因此不包含NP层级的并列结构、介词短语和关系从句。

如果给定语言的noun_chunk syntax iterator尚未实现,则会抛出NotImplementedError错误。

名称描述

Span.as_doc 方法

创建一个新的Doc对象,对应Span,并包含数据的副本。

当对同一文档中的多个跨度调用此方法时,通过使用array_headarray参数传入预先计算好的文档数组表示形式可以节省时间。

名称描述
copy_user_dataWhether or not to copy the original doc’s user data. bool
array_headPrecomputed array attributes (headers) of the original doc, as generated by Doc._get_array_attrs(). Tuple
arrayPrecomputed array version of the original doc as generated by Doc.to_array. numpy.ndarray

Span.root 属性需要模型

与句子根节点路径最短的词符(或根节点本身)。如果多个词符在树中的高度相同,则选择第一个词符。

名称描述

Span.conjuncts 属性需要模型

span.root协调的token元组。

名称描述

Span.lefts 属性需要模型

位于span左侧且其头部在span内的Tokens。

名称描述

Span.rights 属性需要模型

位于span右侧且其头部在span内的Tokens。

名称描述

Span.n_lefts 属性需要模型

位于该跨度左侧且其头部在该跨度内的标记数量。

名称描述

Span.n_rights 属性需要模型

位于该span右侧且其头部在该span内的token数量。

名称描述

Span.subtree 属性需要模型

该跨度内的标记及其派生标记。

名称描述

Span.has_vector 属性需要模型

一个布尔值,表示该对象是否关联了词向量。

名称描述

Span.vector 属性需要模型

一个实值意义表示。默认为词符向量的平均值。

名称描述

Span.vector_norm 属性需要模型

该跨度向量表示的L2范数。

名称描述

Span.sent 属性需要模型

该span所属的句子范围。此属性仅在文档通过parsersentersentencizer或某些自定义函数设置了句子边界时才可用,否则会引发错误。

如果该跨度恰好跨越句子边界,则只会返回第一个句子。如果需要确保句子始终包含完整的跨度,可以按如下方式调整结果:

名称描述

Span.sents 属性v3.2.1需要模型

返回一个生成器,用于遍历该span所属的句子。该属性仅在文档通过parsersentersentencizer或某些自定义函数设置了句子边界时才可用,否则会引发错误。

如果该跨度恰好跨越句子边界,将返回与该跨度重叠的所有句子。

名称描述

属性

名称描述
docThe parent document. Doc
tensorThe span’s slice of the parent Doc’s tensor. numpy.ndarray
startThe token offset for the start of the span. int
endThe token offset for the end of the span. int
start_charThe character offset for the start of the span. int
end_charThe character offset for the end of the span. int
textA string representation of the span text. str
text_with_wsThe text content of the span with a trailing whitespace character if the last token has one. str
orthID of the verbatim text content. int
orth_Verbatim text content (identical to Span.text). Exists mostly for consistency with the other attributes. str
labelThe hash value of the span’s label. int
label_The span’s label. str
lemma_The span’s lemma. Equivalent to "".join(token.text_with_ws for token in span). str
kb_idThe hash value of the knowledge base ID referred to by the span. int
kb_id_The knowledge base ID referred to by the span. str
ent_idThe hash value of the named entity the root token is an instance of. int
ent_id_The string ID of the named entity the root token is an instance of. str
idThe hash value of the span’s ID. int
id_The span’s ID. str
sentimentA scalar value indicating the positivity or negativity of the span. float
_User space for adding custom attribute extensions. Underscore