我正在使用com.hp.hpl.jena.rdf.model.Model.listNameSpaces()来获取Jena RDF模型中的命名空间.
但我注意到模型可以包含listNameSpaces方法未列出名称空间的语句对象.
例如,相机图(http://www-users.cs.york.ac.uk/~jc/teaching/arin/camera.owl.turtle)包含以下对象,但它们的命名空间不会出现在命名空间中列表:
http://www.dbpedia.org/resource/尼康 http://www.w3.org/2001/XMLSchema#十进制
有谁知道为什么那两个ns不会被列出?谢谢.
//精简代码:
Model model = ModelFactory.createDefaultModel();
RDFReader reader = model.getReader("TURTLE");
InputStream in = FileManager.get().open("http://www-users.cs.york.ac.uk/~jc/teaching/arin/camera.owl.turtle");
reader.read(model, in, null);
NsIterator listNameSpaces = model.listNameSpaces();
while (listNameSpaces.hasNext())
{
System.out.println("Namespace from iterator: " + listNameSpaces.next());
}
Run Code Online (Sandbox Code Playgroud) 是否可以使用SHACL来制定对整个数据范围的约束?
例如,我可以要求数据中存在符合特定形状的三元组吗?
我的想法的代码示例:
# DEMO code, currently raises an error!!
@prefix ex: <http://example.org/ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
ex:ObligatoryShape
a sh:NodeShape ;
minCount 1 . # What I want
Run Code Online (Sandbox Code Playgroud)
我的想法是,上述代码将为每个不包含至少一个符合 ex:ObligatoryShape 的数据三元组实例的数据图引发错误- 这包括空数据图。
我试图找出以下之间的区别:
<#blabla> rdf:type owl:Class
Run Code Online (Sandbox Code Playgroud)
和:
<#blabla> a owl:Class
Run Code Online (Sandbox Code Playgroud)
只是a一个捷径吗rdf:type?
我想在Fuseki服务器的Web界面中进行简单的插入查询.我已将端点设置为/update(而不是默认值/sparql).我从https://www.w3.org/Submission/SPARQL-Update/获得以下查询:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT { <http://example/egbook3> dc:title "This is an example title" }
Run Code Online (Sandbox Code Playgroud)
此查询将转换为:
http://localhost:3033/dataset.html#query=PREFIX+dc%3A+%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%0AINSERT+%7B+%3Chttp%3A%2F%2Fexample%2Fegbook3%3E+dc%3Atitle++%22This+is+an+example+title%22+%7D%0A
或
curl http://localhost:3033/infUpdate/update -X POST --data 'update=PREFIX+dc%3A+%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%0AINSERT+%7B+%3Chttp%3A%2F%2Fexample%2Fegbook3%3E+dc%3Atitle++%22This+is+an+example+title%22+%7D%0A' -H 'Accept: text/plain,*/*;q=0.9'使用Share your query按钮可见.
该查询返回以下错误:
Error 400: Encountered "<EOF>" at line 2, column 73.
Was expecting one of:
"where" ...
"using" ...
Fuseki - version 2.4.0 (Build date: 2016-05-10T11:59:39+0000)
Run Code Online (Sandbox Code Playgroud)
Web界面和使用时都会发生错误curl.这可能是什么问题?SELECT查询工作没有问题.通过Web界面上载表单从文件加载三元组也可以.附加问题:正常的帖子请求使用query=和curl版本使用update=,为什么这个不同?
我正在尝试使用SANSA-RDF将海龟RDF文件读入Spark并创建图形.我执行以下代码时收到错误.我错过了什么?
import org.apache.jena.query.QueryFactory
import org.apache.jena.riot.Lang
import org.apache.spark.sql.SparkSession
import net.sansa_stack.rdf.spark.io.rdf._
import net.sansa_stack.rdf.spark.io._
import scala.io.Source
object SparkExecutor {
private var ss:SparkSession = null
def ConfigureSpark(): Unit ={
ss = SparkSession.builder
.master("local[*]")
.config("spark.driver.cores", 1)
.appName("LAM")
.getOrCreate()
}
def createGraph(): Unit ={
val filename = "xyz.ttl"
print("Loading graph from file"+ filename)
val lang = Lang.TTL
val triples = ss.rdf(lang)(filename)
val graph = LoadGraph(triples)
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用main函数调用SparkExecutor
object main {
def main(args: Array[String]): Unit = {
SparkExecutor.ConfigureSpark()
val RDFGraph = SparkExecutor.createGraph()
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个具有结构的文件,但我不知道它是什么格式,也不知道如何解析它.文件扩展名是ttl,但我以前从未遇到过这个问题.
文件中的某些行如下所示:
<http://data.europa.eu/esco/label/790ff9ed-c43b-435c-b6b3-6a4a6e8e8326>
a skosxl:Label ;
skosxl:literalForm "gérer des opérations d’allègement"@fr .
<http://data.europa.eu/esco/label/98570af6-b237-4cdd-b555-98fe3de26ef8>
a skosxl:Label ;
esco:hasLabelRole <http://data.europa.eu/esco/label-role/neutral> , <http://data.europa.eu/esco/label-role/male> , <http://data.europa.eu/esco/label-role/female> ;
skosxl:literalForm "particleboard machine technician"@en .
<http://data.europa.eu/esco/label/aaac5531-fc8d-40d5-bfb8-fc9ba741ac21>
a skosxl:Label ;
esco:hasLabelRole "http://data.europa.eu/esco/label-role/female" , "http://data.europa.eu/esco/label-role/standard-female" ;
skosxl:literalForm "pracovnice denní pé?e o d?ti"@cs .
Run Code Online (Sandbox Code Playgroud)
它继续这样400多MB.对于某些节点,但不是所有节点,都添加了附加属性.
它让我想起了某种形式的XML,但是我没有太多使用不同格式的经验.它看起来像是一个可以作为图形的模型.你知道它是什么数据格式,以及我如何在python中解析它?
我想mybrandofmercedes在OWL中设置对类的限制,这在语法上是否正确?我应该有方括号,如下所示?
mynamespace: mybrandofmercedes rdf:type owl:Class;
mynamespace: mybrandofmercedes
[
rdf:type owl:Restriction;
owl:onProperty mynamespace:hasOwner;
owl:hasValue mynamespace: Anders
]
Run Code Online (Sandbox Code Playgroud) 这是我的SPARQL查询:
String queryString =
"SELECT ?URI "
+ "WHERE{ ?URI ?predicate ?object ."
+ "FILTER regex(?URI, \"p\", \"i\")}";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try
{
ResultSet results = qexec.execSelect();
while(results.hasNext()) {
QuerySolution soln = results.nextSolution();
Resource z = (Resource) soln.getResource("URI");
System.out.println(z.toString());
}
finally {
qexec.close();
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我想选择包含字母P的URI资源。我使用了正则表达式过滤器,但是II没有在输出中得到任何东西,甚至没有空指针异常。
我正在为 Swift 中的 Turtle 格式的 RDF 数据编写解析器。海龟语法将模式定义PN_CHARS_BASE为
[163s] PN_CHARS_BASE ::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
Run Code Online (Sandbox Code Playgroud)
(请参阅W3C Turtle 推荐)。
模式中的最后一组[#x10000-#xEFFFF]超出了 UTF-16 字符串编码的范围。这里需要UTF-32。
这种模式用于匹配,例如,在前缀的第一个字符的字符串前缀,如foaf中foaf:name,数这里不允许。
我想NSRegularExpression用于解析海龟文件。所以为了匹配PN_CHARS_BASE模式,我有以下测试代码:
let PN_CHARS_BASE = "[A-Z]|[a-z]|[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]|[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]|[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u10000-\\uEFFFF]"
do {
let teststr = "9"
let regex = try NSRegularExpression(pattern: PN_CHARS_BASE, options: [])
let matches = …Run Code Online (Sandbox Code Playgroud) regex character-encoding nsregularexpression swift turtle-rdf
turtle-rdf ×9
rdf ×5
regex ×2
semantic-web ×2
sparql ×2
apache-spark ×1
file ×1
fuseki ×1
graph ×1
java ×1
jena ×1
json ×1
namespaces ×1
ontology ×1
owl ×1
rdfs ×1
scala ×1
shacl ×1
swift ×1
xml ×1