依赖分析搜索
depgrep的Python项目详细描述
深度
依赖分析搜索conll-u数据帧
Version 0.1.3
Note: this tool currently doesn't have tests, CI, etc. It is not yet advised to use this tool outside of the depgrep methods provided by the
buzz
library.
安装
pip install depgrep
用法
该工具设计用于处理conll-u文件生成的语料库,并由buzz解析为数据帧。最好的方法是使用buzz对语料库建模,然后使用其depgrep方法。
pip install buzz
然后,在python中:
frombuzzimportCorpuscorpus=Corpus('path/to/conll/files')query='l"have"'# match the lemma "have"
语法
depgrep搜索通过nodes和relations的组合工作,就像这个工具所基于的tgrep2一样。
节点
一个节点针对一个令牌特性(word、引理、pos、wordclass、依赖角色等)。它可以指定为正则表达式或简单的字符串匹配:f/amod|nsubj/
将匹配填充nsubj或amod角色的标记;l"be"
将匹配引理,be。
节点查询的第一部分选择要搜索的令牌属性。它可以是以下任一项:
w : word
l : lemma
p : part of speech tag
x : wordclass / XPOS
f : dependency role
i : index in sentence
s : sentence number
区分大小写由正在搜索的属性的大小写控制:p/VB/
不区分大小写,P/VB/
区分大小写。因此,以下查询匹配以ing,ing,ing结尾的单词:
w/ing$/
对于整个查询的大小写不敏感,请使用case_sensitive=False
关键字参数。
关系
关系指定节点之间的关系。例如,我们可以使用f"nsubj" <- f"ROOT"
来定位由root角色中的节点控制的标称主题。您要查找的是查询中最左边的节点。因此,当上面的查询找到名义上的主题标记时,可以使用反向关系f"ROOT" -> f"nsubj"
返回根标记。
可用关系:
a = b : a and b are the same node
a & b : a and b are the same node (same as =)
a <- b : a is a dependent of b
a <<- b : a is a descendent of b, with any distance in between
a <-: b : a is the only dependent of b
a <-N b : a is descendent of b by N generations
a -> b : a is the governor of a
a ->> b : a is an ancestor of b, with any distance in between
a ->: b : a is the only governor of b (as is normal in many grammars)
a ->N b : a is ancestor of b by N generations
a + b : a is immediately to the left of b
a +N b : a is N places to the left of b
a <| b : a is left of b, with any distance in between
a - b : a is immediately to the right of b
a -N b : a is n places to the right of b
a |> b : a is right of b, with any distance in between
a $ b : a and b share a governor (i.e. are sisters)
a $> b : a is a sister of and to the right of b.
a $< b : a is a sister of and to the left of b.
否定
在一个关系之前添加!
来否定它:f"ROOT" != x"VERB"
将找到非语言根节点。
括号
括号可用于进行更复杂的查询:
f"amod" = l/^[abc]/ <- (f/nsubj/ != x/NOUN/)
以上翻译为match以a、b或c开头的形容词修饰语,这些修饰语由非名词的名词性主语支配
注意,没有括号,每个关系/节点都引用最左边的节点。在下面,复数名词必须与nsubj节点相同,而不是root: 可以使用管道( 上面,我们匹配由root控制或复数的名词。 您可以使用f"nsubj" <- f"ROOT" = p"NNS"
或表达式
|
)创建一个或表达式。# match all kinds of modifiers
x"ADJ" | f"amod" | f"appos" | p/^JJ/
x"NOUN" <- f"ROOT" | = p"NNS"
通配符
__
或*
代表任何令牌。要匹配作为动词调控器的任何标记,请执行以下操作:__ -> x"VERB"
推荐PyPI第三方库