我正在寻找一种用于调用匿名节点的乌龟语法,该匿名节点调用另一个匿名节点.
例如,我想重现这段代码:
:Instance0 a Class0;
:property0 :Instance1.
:Instance1 a Class1;
:property1 :Instance2.
:Instance2 a Class2;
:property2 :Instance1.
Run Code Online (Sandbox Code Playgroud)
有类似的东西:
:Instance0 a Class0;
:property0 [
a Class1;
:property1 [
a Class2;
:property2 [
## The syntax to call the parent, the instance of :Class1
];
];
].
Run Code Online (Sandbox Code Playgroud)
为此目的有没有龟语法?
我有一个.ttl表格的文件.它有4个属性/列,包含以下形式的四元组:
(id, student_name, student_address, student_phoneno). (id, faculty_name, faculty_address, faculty_phoneno).我知道如何.n3使用RDFLib 解析表格三元组;
from rdflib import Graph
g = Graph()
g.parse("demo.nt", format="nt")
Run Code Online (Sandbox Code Playgroud)
但我不确定如何解析这些四倍.
我的目的是解析和提取与特定id有关的所有信息.学生和教师的身份证可以相同.
如何使用RDFLib处理这些四元组并将其用于聚合id?
.ttl文件中的示例代码段:
#@ <id1>
<Alice> <USA> <12345>
#@ <id1>
<Jane> <France> <78900>
Run Code Online (Sandbox Code Playgroud) 我正在尝试用Turtle格式编码一些植物数据,并使用RDFLib从Python读取这些数据.但是,我遇到了麻烦,我不确定是不是因为我的海龟畸形或者我在滥用 RDFLib.
我的测试数据是:
@PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@PREFIX p: <http://www.myplantdomain.com/plant/description> .
p:description a rdfs:Property .
p:name a rdfs:Property .
p:language a rdfs:Property .
p:value a rdfs:Property .
p:gender a rdfs:Property .
p:inforescence a rdfs:Property .
p:color a rdfs:Property .
p:sense a rdfs:Property .
p:type a rdfs:Property .
p:fruit a rdfs:Property .
p:flower a rdfs:Property .
p:dataSource a rdfs:Property .
p:degree a rdfs:Property .
p:date a rdfs:Property .
p:person a rdfs:Property . …Run Code Online (Sandbox Code Playgroud) 我正在尝试过滤用Turtle编写的这个数据库
@prefix : <http://www.essepuntato.it/resource/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@prefix cs: <http://cs.unibo.it/ontology/> .
:pt0001
vcard:category "Poste e Telegrafi"
; vcard:fn "Ufficio Bologna 1"
; vcard:extended-address "Via Cairoli 9, Bologna BO, Italy"
; vcard:latitude "44.504192"
; vcard:longitude "11.338661"
; vcard:tel "051 243425"
; vcard:fax "051 244459"
; cs:opening "Mon, Tue, Wed, Thu, Fri: 0800-1330. Sat: 0800-1230."
; cs:closing "01-01, 01-06, P, LA, 04-25, 05-01, 06-02, 08-15, 11-01, 12-08, 12-25, 12-26: .".
Run Code Online (Sandbox Code Playgroud)
我使用arc2 api,因为RAP不起作用.我写了这段代码,但它不起作用:
<?php
/* ARC2 static class inclusion */
include_once('./arc2/ARC2.php'); …Run Code Online (Sandbox Code Playgroud) 我想创建一个定义rdf:Seq作为rdfs:range对象的属性:
eg:myProperty a rdf:Property;
rdfs:range rdf:Seq;
.
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法来定义存储在中的元素的类型rdf:Seq.例如,我不希望这样:
eg:typeOfElement a rdf:Class;
.
eg:somethingElse a rdf:Class;
.
[] eg:myProperty [
a rdf:Seq;
rdf:_1 [a eg:typeOfElement]; # It's the type I want
rdf:_2 [a eg:typeOfElement]; # It's the type I want
rdf:_3 [a eg:somethingElse]; # I don't want this type
];
.
Run Code Online (Sandbox Code Playgroud)
有没有办法定义rdf:Seq元素只是eg:typeOfElement我定义时的类型eg:myProperty?
(如果需要,我可以使用猫头鹰.)
在以下最小测试用例中:
from rdflib import Graph, Namespace, Literal, RDF
base = "http://test.com/ns"
foobar = Namespace("http://test.com/ns#")
g = Graph(base=base)
g.bind('foobar', foobar)
g.add((foobar.something, RDF.type, Literal('Blah')))
g.add((foobar.something, foobar.contains, Literal('a property')))
g.add((foobar.anotherthing, RDF.type, Literal('Blubb')))
g.add((foobar.anotherthing, foobar.contains, Literal('another property')))
print(g.serialize(format='turtle').decode("utf-8"))
Run Code Online (Sandbox Code Playgroud)
我明白了
@base <http://test.com/ns> .
@prefix foobar: <http://test.com/ns#> .
<#anotherthing> a "Blubb" ;
ns1:contains "another property" .
ns1:something a "Blah" ;
ns1:contains "a property" .
Run Code Online (Sandbox Code Playgroud)
我期望的更像是
@base <http://test.com/ns> .
@prefix foobar: <http://test.com/ns#> .
<#anotherthing> a "Blubb" ;
foobar:contains "another property" .
<#something> a "Blah" ;
foobar:contains "a …Run Code Online (Sandbox Code Playgroud) 以下是我在N3中创建类的方法:
:Person a rdfs:Class.
Run Code Online (Sandbox Code Playgroud)
以下是如何指定特定的ressource是该类的实例:
:Pat a :Person.
Run Code Online (Sandbox Code Playgroud)
问题:我想创建一个包含20000多个实例的类(以编程方式生成).:Pat a :Person.为我的20000个实例编写整体使得本体文件变得冗长.
问题:是否有解决方案使文件变小?
我刚刚导入了jena库来eclipse在rdf-s上工作,这是我的第一次尝试,但我无法读取乌龟(.ttl)文件.
我用以下方式尝试了它:
import java.io.*;
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
public class Simpsons {
public static void main(String[] args) throws IOException {
Model model=ModelFactory.createDefaultModel();
model.read(new FileInputStream("simpsons.ttl"),null);
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
Exception in thread "main" org.apache.jena.riot.RiotException: [line: 1, col: 1 ] Content is not allowed in prolog.
at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:136)
at org.apache.jena.riot.lang.LangRDFXML$ErrorHandlerBridge.fatalError(LangRDFXML.java:252)
at com.hp.hpl.jena.rdf.arp.impl.ARPSaxErrorHandler.fatalError(ARPSaxErrorHandler.java:48)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.warning(XMLHandler.java:209)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.fatalError(XMLHandler.java:239)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) …Run Code Online (Sandbox Code Playgroud) 在RDF图的Turtle序列化中,我有很多像这样的三元组(许多个体,都具有常见的类型值):
:A a :b .
:B a :b .
:C a :b .
:D a :b .
# …
:Z a :b .
Run Code Online (Sandbox Code Playgroud)
有没有办法在乌龟中简洁地写这个?在SPARQL中,它与Turtle有一些相似之处,我们可以写:
:b ^a :A, :B, :C, …, :Z .
Run Code Online (Sandbox Code Playgroud)
在龟中有对应物吗?
turtle-rdf ×10
rdf ×7
python ×3
rdflib ×2
semantic-web ×2
syntax ×2
blank-nodes ×1
debugging ×1
java ×1
jena ×1
n3 ×1
owl ×1
parsing ×1
php ×1
python-2.7 ×1
rdfs ×1
sparql ×1