Daily Archives: December 15, 2011

Truy xuất dữ liệu từ file .owl sử dụng OWL API

OWL API là một framework khác cũng dùng để truy xuất dữ liệu từ file .owl và các file Ontology-based nói chung.

Để truy xuất các classes dưới một Restriction property, ta có đoạn mã sau (sử dụng Java):


for (OWLSubClassAxiom ax : ont.getSubClassAxiomsForLHS(margheritaPizza)) { OWLDescription superCls=null;

try {
 superCls = ax.getSuperClass();
 superCls.accept(restrictionVisitor);
 OWLObjectSomeRestriction someValuesFrom = (OWLObjectSomeRestriction) superCls;
 OWLDescription filler = someValuesFrom.getFiller();
 System.out.println(" " + filler);

} catch (Exception e) {
 try{
 OWLObjectAllRestriction allValuesFrom = (OWLObjectAllRestriction) superCls;
 OWLDescription filler = allValuesFrom.getFiller();
 System.out.println(" " + filler);
 }catch(Exception ex)
 {
 // System.out.println(ex.getMessage());
 }

 }
 }

Lệnh getFiller() sẽ trả về cho ta toàn bộ các classes có trong các object của restriction property.

Kết quả trên Netbean(ví dụ tìm cho loại Pizza có tên là Cajun):

 

So sánh với CSDL có sẵn trên Protege Ontology 3.4.7: