依赖分析搜索

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搜索通过nodesrelations的组合工作,就像这个工具所基于的tgrep2一样。

节点

一个节点针对一个令牌特性(word、引理、pos、wordclass、依赖角色等)。它可以指定为正则表达式或简单的字符串匹配:f/amod|nsubj/将匹配填充nsubjamod角色的标记;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/区分大小写。因此,以下查询匹配以inginging结尾的单词:

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

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"

上面,我们匹配由root控制或复数的名词。

通配符

您可以使用__*代表任何令牌。要匹配作为动词调控器的任何标记,请执行以下操作:

__ -> x"VERB"

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java基于条件如何创建StringBuffers并向其添加数据   java如何用UNC路径解决“不表示可正确访问的目录”异常?   在执行提取方法重构后,java代码的速度降低了6倍   java如何修改LDAPCertStore中用于X509证书链验证的LDAP连接属性   awt如何在Java中捕获鼠标光标?   字符串如何设置Java输出流   java NumberFormatException:用于输入字符串:“8:00”   unix/linux“tail f”的Java IO文件实现   java打印输出。带有JOptionPane的txt文件   java解组总是显示0和null   使用MySQL的windows java JavaFX自包含应用程序打包   JavaSpring:方法getBean(String…)是如何实现的根据输入字符串查找bean?   java高效地更新RecyclerView网格或以其他方式显示复杂网格   java向ArrayList添加对象(String、String、int、int)   java在一组文档上使用ForkJoinPool