我的 RDF:
<rdf:Description rdf:about="http://earthquake.linkeddata.it/resource/Isolator">
<owl:equivalentClass rdf:resource="http://earthquake.linkeddata.it/resource/VibrationAbsorber"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="http://earthquake.linkeddata.it/resource/MagnetoRheological(MR)damper">
<owl:equivalentClass rdf:resource="http://earthquake.linkeddata.it/resource/**SemiActiveDamper**"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
我的代码:
public static void main (String args[]) throws IOException,InterruptedException {
// create an empty model
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,null);
// use the class loader to find the input file
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException( "File: " + inputFileName + " not found");
}
// read the RDF/XML files
m.read( in, "" );
Scanner user_input=new Scanner(System.in);
String input;
System.out.print("Enter your concept");
input= user_input.next();
ExtendedIterator<?> i1 = m.listClasses();
while(i1.hasNext()){
OntClass oc = (OntClass)i1.next();
if( oc.getEquivalentClass() != null){
input=oc.getEquivalentClass().toString();
System.out.println("Equivalent Class name: "+oc.getEquivalentClass().getLocalName());
}
}
使用这段代码,我得到了一个等价类的列表,例如 SemiActiveDamper 和 VibrationAbsorber。但我的目标只是根据用户输入获得 SemiActiveDamper 或 VibrationAbsorber。我该如何解决这个问题?