How to query RDF/OWL using SWI-Prolog's Semantic Web Library?

泪湿孤枕 提交于 2019-12-20 12:35:58

问题


How can I use the SWI-Prolog Semantic Web Library to make a query into the OWL/RDF file and extract some information?

The OWL/RDF file is having information about all the Debian packages so I need to make the query in order to find package dependencies.

For Example:

The OWL file is structured as follows:

package: A

Depends:

package: B

pacakge: C

How can I load a OWL/RDF file into a Prolog script and what is the syntax to make a query within the Prolog script such that I put A as a parameter and the script outputs B and C?


回答1:


This is how you load the semweb library:

?- use_module(library(semweb/rdf_db)).

This is how you parse an RDF/XML file and backtrack over all its subject-predicate-object triples:

?- rdf_load('file.owl'), rdf(X, Y, Z).
% Parsed "file.owl" in 0.06 sec; 2,107 triples
X = 'http://www.co-ode.org/ontologies/pizza/pizza.owl',
Y = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
Z = 'http://www.w3.org/2002/07/owl#Ontology' ;
X = 'http://www.co-ode.org/ontologies/pizza/pizza.owl',
Y = 'http://www.w3.org/2002/07/owl#versionInfo',
Z = literal(type('http://www.w3.org/2001/XMLSchema#string', 'version 1.5')) ;


来源:https://stackoverflow.com/questions/6327167/how-to-query-rdf-owl-using-swi-prologs-semantic-web-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!