Java jena如何将默认前缀名称更改为我的前缀名称
我已经生成了这个RDF/XML数据Java jena如何将默认前缀名称更改为我的前缀名称,java,jena,semantic-web,owl,apache-jena,Java,Jena,Semantic Web,Owl,Apache Jena,我已经生成了这个RDF/XML数据 土木工程部 十二月 新闻部 代伊 电气工程部 迪伊 使用此代码: String myNameSpace = "http://william_student/"; Resource departmentClass = ResourceFactory.createResource(myNameSpace+"Department"); Property abbreviationProperty = Resource
土木工程部
十二月
新闻部
代伊
电气工程部
迪伊
使用此代码:
String myNameSpace = "http://william_student/";
Resource departmentClass = ResourceFactory.createResource(myNameSpace+"Department");
Property abbreviationProperty = ResourceFactory.createProperty(myNameSpace, "abbreviation");
Property descriptionProperty = ResourceFactory.createProperty(myNameSpace, "description");
Model departmentModel = ModelFactory.createDefaultModel();
Resource departmentInstance1 = departmentModel.createResource();
departmentInstance1.addProperty(RDF.type, departmentClass);
departmentInstance1.addProperty(abbreviationProperty, "DEI");
我用这个简单的代码写文件
File file = new File("D:/departments.rdf");
fos = new FileOutputStream(file);
departmentModel.write(fos);
如您所见,在RDF生成的数据中,有j.0
前缀:
我的问题:
如何替换默认前缀
j.0
,但我的前缀如vocabularyMarco
要编写RDF/XML,所有属性都必须有一个qname。杰娜发明了“j.0”等,当一个是需要的,但没有提供。因此,请在模型上设置您选择的前缀名称
model.setNsPrefix("vocabularyMarco", "http://marco_student/")
您的代码和数据在“”上不一致
它在上述代码段中创建前缀“citylsdi.org”
为了得到“vocabularyMarco”作为前缀
只用
// Namespace declarations
static final String companyUri = "citylsdi.org#";
Model model = ModelFactory.createDefaultModel();
model.setNsPrefix( "Indicator", "citylsdi.org#" );
Model model = ModelFactory.createDefaultModel();
model.setNsPrefix( "Indicator", "vocabularyMarco" );
// Create the types of Property we need to describe relationships in the model
Property cu_role = model.createProperty(companyUri,domain);
// Create resources representing the people in our model
Resource rs2 = model.createResource(companyUri+name);
rs2.addProperty(cu_role,"'"+role+"'");