Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jena如何将默认前缀名称更改为我的前缀名称_Java_Jena_Semantic Web_Owl_Apache Jena - Fatal编程技术网

Java jena如何将默认前缀名称更改为我的前缀名称

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

我已经生成了这个RDF/XML数据


土木工程部
十二月
新闻部
代伊
电气工程部
迪伊
使用此代码:

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+"'");