如何获得等效类取决于用户输入?

时间:2013-08-26 09:15:36

标签: java jena

我的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。我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:2)

重复http://answers.semanticweb.com/questions/24208/how-to-get-equivalent-class-depends-on-user-input

在等效类

的URi上使用字符串比较

更好 - 为类添加用户可读标签并搜索这些标签。

相关问题