sparQL中的数据属性值

时间:2017-12-19 11:30:16

标签: java sparql owl

我是OWL和sparql的新手 我遇到了错误,我真的需要你的帮助 让我解释 这是我的本体论保护 ontology.owl

这是我在eclispe上的java代码:

public class speakUpdate {

public static void main(String[] args) {

    String fileName="C:/Users/User/Desktop/Software Engineering Level 4/FInal Year Project/translation.owl";
    OntModel model=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);

    try 
    {
        File file = new File(fileName);
        FileReader reader=new FileReader(file);
        model.read(reader,null);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    String phrase="have application";

    String SparQLSubClassOfKeyWord= 
            "prefix ns:<http://www.semanticweb.org/umar/ontologies/translation.owl#>"+
            "prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>"+

            "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+

            "select ?subClass "+
            "where { ?subClass rdfs:subClassOf ns:keyWords ."
            + "}";                                                                                      

    System.out.println( "== useParameterizedSPARQLString ==" );


    // execute the query that finds a (single) binding for ?subClass.  Then create
    // a query solution map containing those results.

    final ResultSet SubclassResults = QueryExecutionFactory.create( SparQLSubClassOfKeyWord, model ).execSelect();
    final QuerySolutionMap mapSubClass = new QuerySolutionMap();

        do
        {
            mapSubClass.addAll(SubclassResults.next());

             System.out.println("mapSubClass contains");
             System.out.println(mapSubClass);

            Resource resoursubClass=mapSubClass.getResource("?subClass");
            String StringSubClass=resoursubClass.toString();
            String subClassName=StringSubClass.substring(StringSubClass.lastIndexOf("#")+1);

            if ( phrase.toLowerCase().indexOf(subClassName.toLowerCase()) != -1 ) 
            {
                System.out.println("I found the keyword "+subClassName);

                String SparQlIndividual=
                        "prefix ns:<http://www.semanticweb.org/umar/ontologies/translation.owl#>"+
                        "prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>"+
                        "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+

                        "select ?individual ?subClass ?dataP"+
                        "where {"
                        + "?individual rdf:type ?subClass ."
                        + "?individual ns:PathAudio ?dataP ."
                        + "}";


                        final ParameterizedSparqlString p1 = new ParameterizedSparqlString( SparQlIndividual );

                        p1.setParams( mapSubClass );
                        ResultSetFormatter.out( 
                        QueryExecutionFactory.create( p1.toString(), 
                        model).execSelect() ); 

                        break;
              } 
              else 
              {
                //Did not found the keyword
                mapSubClass.clear();
              } 
          }       
          while(SubclassResults.hasNext());
   }
 }

我在我的本体中搜索关键词,从而检索其相关个体及其数据属性值

但是我遇到了以下错误,我坚持不懈:

    == useParameterizedSPARQLString ==
    mapSubClass contains
    ( ?subClass, :payment )
    mapSubClass contains
    ( ?subClass, :information )
    mapSubClass contains
    ( ?subClass, :complaint )
    mapSubClass contains
    ( ?subClass, :application )
    I found the keyword application
    Exception in thread "main" org.apache.jena.query.QueryParseException: 
    Encountered " <IRIref> "
    <http://www.semanticweb.org/umar/ontologies/translation.owl#application> 
    "" at line 1, column 198.
 Was expecting one of:
<VAR1> ...
<VAR2> ...
"from" ...
"where" ...
"(" ...
"{" ...

at org.apache.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:100)
at org.apache.jena.sparql.lang.ParserSPARQL11.parse$(ParserSPARQL11.java:52)
at org.apache.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:34)
at org.apache.jena.query.QueryFactory.parse(QueryFactory.java:147)
at org.apache.jena.query.QueryFactory.create(QueryFactory.java:79)
at org.apache.jena.query.QueryFactory.create(QueryFactory.java:52)
at org.apache.jena.query.QueryFactory.create(QueryFactory.java:40)
at org.apache.jena.query.QueryExecutionFactory.makeQuery(QueryExecutionFactory.java:564)
at org.apache.jena.query.QueryExecutionFactory.create(QueryExecutionFactory.java:141)
at speakUpdate.main(speakUpdate.java:89)

我可以请别人帮助我 非常感谢提前

0 个答案:

没有答案