-1

したがって、[Aa、Bb、Cc、..] の形式の文字列を持つこの List strarray を入力として使用します。リストの各要素に対して同じクエリを実行する必要があります。保持するものをユーザーが選択してから、これらの結果を文字列に追加します。文字列の出力は次のようになります。

私のコードでは結果が返されません。おそらくループの問題を扱っているからです。どうすればこれを機能させることができますか?

public static List<String> strarray = new ArrayList<String>() ;

for(int i =0;i<strarray.size(); i++){

        String selec1 = strarray.get(i);


        String queryString2 =
                "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +        
                "PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
                "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " +
                "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
                "PREFIX bi: <#> " +

    "SELECT ?X " +
    " WHERE {?X bi:has_input <"+selec1+">} " ;

        Query query2 = QueryFactory.create(queryString2);

        QueryExecution qe2 = QueryExecutionFactory.create(query2, model);
        com.hp.hpl.jena.query.ResultSet results3 =  qe2.execSelect();
        ResultSet results4 = ResultSetFactory.copyResults(results3);
        final ResultSet results5 = ResultSetFactory.copyResults(results4);

        System.out.println("==== Available Options ====");
        ResultSetFormatter.out(System.out, results4, query2);


        System.out.println( "== Select Option ==" );
        System.out.println( "== Type 0,1,2,3.. to choose ==" );

        Scanner input = new Scanner( System.in );
        final String inputs ;
        inputs = input.next();


   final String[] indices = inputs.split("\\s*,\\s*");


        final List<QuerySolution> selectedSolutions = new ArrayList<QuerySolution>( indices.length ) {{
            final List<QuerySolution> solutions = ResultSetFormatter.toList(results5);
            for ( final String index : indices ) {
                add( solutions.get( Integer.valueOf( index )));
            }
        }};


        String s = selectedSolutions.toString();


         String newstr;
          newstr = s.replaceAll("_", "");

          List<String> temp1 = new ArrayList<String>() ;

          Pattern p = Pattern.compile("#([^>]+)>");
           Matcher m = p.matcher(newstr);


           while (m.find()) {
               temp1.add(m.group(1));
            }         

           String selecfin = null;

           for(int j =0;j<temp1.size(); j++){
           String selecP = temp1.get(j);

           selecfin = selec1+".("+selecP+")";
           System.out.println(selecfin);
           }
           System.out.println(selecfin);
        }
4

1 に答える 1

0

クエリの入力に問題がありました。以前にコードで _ を置き換えたのを忘れていました。したがって、クエリは個人を認識しません。問題が解決しました。ありがとう

于 2013-09-19T15:36:04.720 に答える