我在 AllegroGraph 中注册命名空间时遇到问题。
我的Java代码(程序1):
AllegroGraphConnection agc = new AllegroGraphConnection();
agc.enable();
AllegroGraph ag = agc.create("test", AGPaths.TRIPLE_STORES);
AGUtils.printStringArray("AG Namespaces (initially):", ag.getNamespaces());
ag.registerNamespace("foaf","http://xmlns.com/foaf/0.1/");
ag.registerNamespace("dc", "http://purl.org/dc/elements/1.1/");
ag.registerNamespace("dct", "http://purl.org/dc/terms/");
ag.registerNamespace("exif","http://www.w3.org/2003/12/exif/ns#");
ag.registerNamespace("prf", "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-2007511#");
AGUtils.printStringArray("AG Namespaces (registed):", ag.getNamespaces());
运行,结果(程序1):
AG 命名空间(初始):
0:rdf
1:http://www.w3.org/1999/02/22-rdf-syntax-ns#
2:rdfs
3:http://www.w3.org/2000/01/rdf-schema#
4:猫头鹰
5:http://www.w3.org/2002/07/owl#
AG 命名空间(已注册):
0: rdf
1: http://www.w3.org/1999/02/22-rdf-syntax-ns#
2: rdfs
3: http://www.w3.org/2000/01/rdf-schema#
4: owl
5: http://www.w3.org/2002/07/owl#
6: foaf
7: http://xmlns.com/foaf/0.1/
8: dc
9: http://purl.org/dc/elements/1.1/
10: dct
11: http://purl.org/dc/terms/
12: exif
13: http://www.w3.org/2003/12/exif/ns#
14: prf
15: http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-2007511#
然后,我的Java代码(程序2):
AllegroGraphConnection agc = new AllegroGraphConnection();
agc.enable();
AllegroGraph ag = agc.open("test", AGPaths.TRIPLE_STORES);
AGUtils.printStringArray("AG Namespaces (registed):", ag.getNamespaces());
运行,结果(程序2):
AG 命名空间(已注册):
0: rdf
1: http://www.w3.org/1999/02/22-rdf-syntax-ns#
2: rdfs
3: http://www.w3.org/2000/01/rdf-schema#
4: owl
5: http://www.w3.org/2002/07/owl#
在程序1中,我创建了一个名为“test”的AllegroGraph
,
我注册了其他 5 个命名空间(foaf、dc、dct、exif、prf);
在程序2中,我打开创建的AllegroGraph,但是它的命名空间只有3个:rdf,rdfs,owl,
程序 1 中注册的其他 5 个命名空间丢失。
我的问题是:
- 为什么其他 5 个命名空间漏掉了?
- 如何在创建的
AllegroGraph
中保留 5 个已注册的命名空间? (当我打开创建的AllegroGraph
时,我不需要再次注册命名空间。)
在我的程序中,注册所有 namespace 后,我添加了以下代码:
ag.closeTripleStore();
它没有用:(
最佳答案
简而言之,AllegroGraph 不会在三重存储中保留命名空间注册。命名空间是一种语法糖,它的存在是为了让长 URI 的读写变得更加容易。尽管有许多常用的缩写(rdf、owl、foaf、dc...),但每个人都可以自己编写并按自己认为合适的方式使用它们。如果 AllegroGraph 保留命名空间缩写,则商店将带有某人的个人缩写,如果其他人打开商店,这可能会导致困惑。
简而言之,如果您想使用命名空间,您应该设置代码以在启动时重新注册它们。另请注意,命名空间缩写对于正在运行的实例是全局的,而不是特定的三元组存储。
HTH
关于java - 在 AllegroGraph 中注册命名空间(缺少注册的命名空间。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2190131/