1

任何人都知道如何在 Jena 的 protege 中添加数据属性。我可以轻松地添加对象属性,但对于数据属性不知何故不起作用,而不是在数据属性断言中添加属性,而是添加注释。也许我的代码有问题?

代码

 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();
4

1 回答 1

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://...");
于 2013-02-06T18:46:50.380 回答