访问trips本体和词典的简单python包

pytrips的Python项目详细描述


PyTrips PyPI version

Build Status

pytrips提供了一个与trips本体和解析器交互的python接口。

安装

pip install pytrips
pip install pytrips[tools] # optional
python -c "import nltk; nltk.download('wordnet')"

基本用法

加载本体并按名称检索类型:

from pytrips.ontology import load
ont = load()

catch = ont["catch"] # lookup an ontology type

然后检查所述类型:

print(catch)
print(catch.parent)
print(catch.children)
print(catch.arguments)

结果应该是:

# ont::catch
# ont::co-motion
# []
# [<TripsRestriction :neutral >, <TripsRestriction :source >, <TripsRestriction :result >, <TripsRestriction :extent >, <TripsRestriction :affected >, <TripsRestriction :agent >]

检查类型是否互相包含:

catch < ont["event-of-action"]

# Make sure at least one type is explicitly a TripsType.  The other can be a string.
"food" > ont["bread"]

或者得到两种类型的最低公共subsumer:

ont["bread"] ^ ont["geo-object"]

为了简单起见,以相同的方式查找单词和本体类型:

ont["person"] # default is to look up an ontology type
ont["ont::person"] # explicitly get the ontology type named "ont::person"
ont["w::person"] # or lookup the list of ontology types that the word "person" can map to

wordnet查找类似:

ont["wn::cat%1:06:00::"]
>> [ont::device]

ont["q::cat"] # returns all lexical and wordnet mappings for the word cat in a dictionary
>> {'lex': [ont::nonhuman-animal, ont::medical-diagnostic],
 'wn': [ont::pharmacologic-substance,
  ont::female-person,
  ont::communication-party,
  ont::male-person,
  ont::medication,
  ont::mammal,
  ont::device,
  ont::land-vehicle,
  ont::vomit]}

或者我们可以指定词性来限制搜索:

ont[("q::move", 'v')]
>> {'lex': [ont::cause-move, ont::move, ont::provoke, ont::activity-ongoing],
 'wn': [ont::cause-effect,
  ont::change,
  ont::believe,
  ont::activity-event,
  ont::commerce-sell,
  ont::move,
  ont::progress,
  ont::live,
  ont::suggest]}

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

推荐PyPI第三方库


热门话题
java JavaFX 11可编辑组合框引发IndexOutOfBoundsException   java选择数组中的数组元素   java我从来没有找到创建2D ArrayList的正确方法   java JPA查找orderById的顶部数据,并按字符串过滤Id   使用java在ejabberd中进行xmpp外部身份验证   从ajax调用向java传递点运算符   java如何使用ReadWriteLock   使用Spring控制器和jQueryAjax的java重定向   java使JFrame中的JPanel可滚动   java如何用多个。jar库?   java EditText在RecyclerView中失去了对滚动的关注   java为什么我们必须扩展Servlet或GenericServlet或HttpServlet来创建Servlet应用程序?如果不扩展,我们可以开发Servlet应用程序吗?   使用递归java查找数组中的最大值   具有不同字段数的html表单的java域传输对象   java文本视图扩展;不支持操作异常   java如何使用iText的HTMLWorker类将多语言HTML字符串呈现为PDF