使用Jena添加Data Property

时间:2013-02-06 18:00:43

标签: jena

任何人都知道如何添加数据属性以保护Jena。我可以很容易地添加对象属性但是对于数据属性不知何故不起作用,而不是在数据属性断言中添加属性它添加了注释。我的代码可能有问题吗?

代码

 OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, null);


            String NS = "http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology#";
            model.read(in, null);
            in.close();

            OntClass ApplicationModel = model.getOntClass(NS + "ApplicationModel");

            Individual AM20 = model.createIndividual(NS + xmlDoc.getDocumentElement().getAttribute("guid")+ theAttribute.getNodeValue(), ApplicationModel);

            Individual dom = model.getIndividual(NS + domainElement.getAttribute(attrDomain));
            Individual pha = model.getIndividual(NS + neededString.trim());
            Individual lev =  model.getIndividual(NS + lodElement.getAttribute(attrLOD));
            Individual typ = model.getIndividual(NS + theAttrType.getNodeValue());

            Property urlAdd =  model.createProperty(NS + "http://xxxxx.com");

            // Create Object Property
            ObjectProperty domain = model.createObjectProperty(NS +"hasDomain");
            ObjectProperty fase = model.createObjectProperty(NS +"hasPhase");
            ObjectProperty lod = model.createObjectProperty(NS +"hasLevelOfDetail");
            ObjectProperty type = model.createObjectProperty(NS +"hasType");

            model.add(AM20, domain, dom);
            model.add(AM20, fase, pha);
            model.add(AM20, lod, lev);
            model.add(AM20, type, typ);

            // Create Data Property
            DatatypeProperty url = model.createDatatypeProperty(NS + "hasURL");

            model.add(AM20, url, urlAdd );

            PrintStream p= new PrintStream("./src/thesis_ontology.owl");
            model.write(p, "RDF/XML-ABBREV", null);
            p.close();

1 个答案:

答案 0 :(得分:4)

我想我发现了这个问题。希望有一天能帮助别人:D

代码应该是这样的

 OntClass ApplicationModel = model.getOntClass(NS + "ApplicationModel");

            Individual AM20 = model.createIndividual(NS + xmlDoc.getDocumentElement().getAttribute("guid")+ theAttribute.getNodeValue(), ApplicationModel);

            Individual dom = model.getIndividual(NS + domainElement.getAttribute(attrDomain));
            Individual pha = model.getIndividual(NS + neededString.trim());
            Individual lev =  model.getIndividual(NS + lodElement.getAttribute(attrLOD));
            Individual typ = model.getIndividual(NS + theAttrType.getNodeValue());


            // Create Object Property
            ObjectProperty domain = model.createObjectProperty(NS +"hasDomain");
            ObjectProperty fase = model.createObjectProperty(NS +"hasPhase");
            ObjectProperty lod = model.createObjectProperty(NS +"hasLevelOfDetail");
            ObjectProperty type = model.createObjectProperty(NS +"hasType");

            model.add(AM20, domain, dom);
            model.add(AM20, fase, pha);
            model.add(AM20, lod, lev);
            model.add(AM20, type, typ);

            // Create Data Property
            DatatypeProperty url = model.createDatatypeProperty(NS + "hasURL");

            model.add(AM20, url, "http://...");
相关问题