Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.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 OWLAPI在子类断言上设置DataProperty严格值_Java_Protege_Owl Api - Fatal编程技术网

Java OWLAPI在子类断言上设置DataProperty严格值

Java OWLAPI在子类断言上设置DataProperty严格值,java,protege,owl-api,Java,Protege,Owl Api,我可以使用此代码创建受限制的数据范围: public void testDatatypeRestriction() throws OWLException { OWLOntologyManager m = create(); OWLOntology o = m.createOntology(EXAMPLE_IRI); // Adults have an age greater than 18. OWLDataProperty ha

我可以使用此代码创建受限制的数据范围:

 public void testDatatypeRestriction() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = m.createOntology(EXAMPLE_IRI);
        // Adults have an age greater than 18.
        OWLDataProperty hasAge = df.getOWLDataProperty(IRI.create(EXAMPLE_IRI + "hasAge"));
        // Create the restricted data range by applying the facet restriction
        // with a value of 18 to int
        OWLDataRange greaterThan18 = df.getOWLDatatypeRestriction(df.getIntegerOWLDatatype(), OWLFacet.MIN_INCLUSIVE, df
            .getOWLLiteral(18));
        // Now we can use this in our datatype restriction on hasAge
        OWLClassExpression adultDefinition = df.getOWLDataSomeValuesFrom(hasAge, greaterThan18);
        OWLClass adult = df.getOWLClass(IRI.create(EXAMPLE_IRI + "#Adult"));
        OWLSubClassOfAxiom ax = df.getOWLSubClassOfAxiom(adult, adultDefinition);
        m.applyChange(new AddAxiom(o, ax));
    }
现在我需要知道如何以编程方式将类定义为具有严格值的dataproperty断言的子类:

Alex:owlClass
HasAge:DataProperty

Alex HasAge value 35

附言:两个答案都是正确的。但是@ssz答案更接近问题的答案,它同时适用于hermit和pellet reasoner


在公理上的pellet推理似乎存在一些问题,如
hasAge xsd:integer[>=20,屏幕截图显示,另请参见。
从编程角度看,这如下所示:

String EXAMPLE_IRI = "https://stackoverflow.com/questions/65793751#";

OWLDataFactory df = m.getOWLDataFactory();
OWLDataProperty hasAge = df.getOWLDataProperty(IRI.create(EXAMPLE_IRI + "hasAge"));
OWLClass adult = df.getOWLClass(IRI.create(EXAMPLE_IRI + "Adult"));

// SubClassOf(:Adult DataHasValue(:hasAge "35"^^xsd:integer))
OWLAxiom ax = df.getOWLSubClassOfAxiom(adult, df.getOWLDataHasValue(hasAge, df.getOWLLiteral(35)));
System.out.println(ax);
System.out.println("---------------");

OWLOntology ont = m.createOntology();
ont.add(ax);    
ont.saveOntology(new ManchesterSyntaxDocumentFormat(), System.out);

数据属性表示个人和值之间存在链接。它不能用于表示类与值链接。最接近的说法是,您的类
Alex
是类
hasAge value 35
的子类,这是您在屏幕截图中看到的。您的代码不链接个人l到一个值。它将
成人
定义为类
hasAge>=18
@HenrietteHarmse的子类。你是对的。那么让我们说一下如何通过编程断言:
Alex
类是
hasAge值35
的子类?@HenrietteHarmse呢?是的,这是更准确的答案。我需要指定hasAge值(35)作为一个整数而不是文本。我该怎么做呢?在OWL中没有“整数”这样的东西。只有带有某些数据类型的文本,例如带有
xsd:int
xsd:integer
。只要试着玩代码并访问链接就可以了。
hasAge value 35
-是用于DataHasValue限制的曼彻斯特语法字符串,在函数语法中是确定类似于
DataHasValue(:hasAge“35”^^xsd:integer)