簡體   English   中英

在沒有sparql的情況下檢索對象的謂詞和謂詞

[英]Retrieving object and predicate for a subject without sparql

我使用getSubject()通過模型檢索了主題,為此主題我想為其各自的對象和謂詞創建一個關系。 如何在沒有sparql的情況下通過耶拿檢索對象並為特定主題斷言?

要獲得給定模型m的特定主題的所有謂詞和賓語:

// The resource you already had:
Resource subject; // = m.getResource(NAMESPACE + "subject");

// This creates a 'list' (iterator) over all the satements containing your subject
StmtIterator stmtIterator = m.listStatements(subject, null, (RDFNode) null);

// While you have not processed all these statements:
while (stmtIterator.hasNext()){

     // Grab the next statement
     Statement s = stmtIterator.next();

     // Retrieve the predicate(property) and the object from the statement
     Property predicate = s.getPredicate();
     Resource object = s.getObject();

     // Do something with your predicate
     // Do something with your object
}

但是,如果您要從模型中獲取一個謂詞和一個主題,以將其添加到檢索到的主題中,則:

Property property = m.getProperty(NAMESPACE + "propertyName");
Resource object = m.getResource(NAMESPACE + "objectName");
subject.addProperty(property, object);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM