0

标题可能有点令人困惑,但基本上这就是问题所在:我正在使用JenaPellet 推理器从名为Patient_Doug的资源中生成属性文字。三元组看起来像这样: Patient_Doug-> hasSuggestion-> Literal推断的建议。

问题是 Protege Pellet 推理器为Doug提出了三个建议,因为Doug在医院的情况非常糟糕。Protege 推理器建议Doug需要一张Hi-Lo 床、一个RF ID 带一张靠近护士站的床。不幸的是,在耶拿,我只能打印Hi-lo 床。只有 3 个文字之一。

这是一些代码。

    OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );

    String ns = "http://altervista.org/owl/unit.owl#";
    String inputFile = "c:\\jena\\acuity.owl";  
    InputStream in = FileManager.get().open(inputFile);
    if (in == null) {
        throw new IllegalArgumentException("File: " + inputFile + " not found");
    }
    model.read(in,"");

    model.prepare();

    //inf and reasoner wont run unless i use hp libraries!

    //asserted data properties
    Individual ind = model.getIndividual(ns+"Patient_Doug");
    OntProperty abcValue = model.getOntProperty("http://example.org/hasABCValue");


    //inferred data properties
    OntProperty suggestion = model.getOntProperty(ns+"hasSuggestion");

    //print asserted data properties
    System.out.println("Properties for patient "+ind.getLocalName().toString());
    System.out.println( abcValue.getLocalName()+"= "+ind.getPropertyValue(abcValue).asLiteral().getInt());

    //print inferenced data properties      
    StmtIterator it = ind.listProperties(suggestion);

     //this iterator only prints one suggestion in an infinite loop
    while (it.hasNext()) {
        System.out.println("A posible suggestion= "+ind.getPropertyValue(suggestion).asLiteral().getString());
    }

    }

代码工作正常,但最后的迭代器在无限循环中只打印一个subggestion

我将不胜感激任何建议。谢谢。

4

1 回答 1

0

此代码用于迭代和打印许多推断的 hasSuggestions。hasSuggestion SWRL 规则在 OWL 本体中

    OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );

String ns = "http://altervista.org/owl/unit.owl#";
String inputFile = "c:\\jena\\acuity.owl";  
InputStream in = FileManager.get().open(inputFile);
if (in == null) {
    throw new IllegalArgumentException("File: " + inputFile + " not found");
}
model.read(in,"");

model.prepare();

//inf and reasoner wont run unless i use hp libraries!

//asserted data properties
Individual ind = model.getIndividual(ns+"Patient_Doug");
OntProperty abcValue = model.getOntProperty("http://example.org/hasABCValue");


//inferred data properties
OntProperty suggestion = model.getOntProperty(ns+"hasSuggestion");

//print asserted data properties
System.out.println("Properties for patient "+ind.getLocalName().toString());
System.out.println( abcValue.getLocalName()+"= "+ind.getPropertyValue(abcValue).asLiteral().getInt());

    for (StmtIterator j = ind.listProperties(suggestion); j.hasNext(); ) {
            Statement s = j.next();
            //System.out.println( "    " + s.getPredicate().getLocalName() + " -> " );
            System.out.println( "A possible suggestion... " + s.getLiteral().getLexicalForm());

        }
于 2018-01-14T03:22:53.793 回答