1

パラメータ化されたクエリを dotNetRDF の ExecuteQery() 関数に渡そうとしています

私のコードは

   preference =  (d1.send()); // d1.send(); method returns a string value


   SparqlParameterizedString queryString = new SparqlParameterizedString();
   queryString.CommandText = @"
   PREFIX my: <http://www.codeproject.com/KB/recipes/n3_notation#>
   SELECT ?name WHERE { [ a my:spec; my:preferedby my:@variable;  my:name ?name].  }";

   queryString.SetVariable("variable", preference );

preference関数の2番目のパラメーターに変数を設定できませんSetVariable。これは、無効な引数であると言われているためです。パラメータは値でなければならないというドキュメントを読みました。使用してINode変数の INode 値を取得しようとしましたpreference

INode value = preference.Value("var");

エラーが表示されるため実行できません」String does not contain a definition for value"

この文字列変数の INode 値を取得する方法、またはこのSetVariableメソッドを正しく呼び出す方法を教えてください。

4

1 に答える 1

1

まず、クエリ テンプレートが見栄えが悪く、my:@variable注入した値に関係なく、無効なクエリが発生するだけです。また、パラメータであり、またはメソッド@variableのいずれかを介して注入する必要があります。SetParameter()SetUri()SetLiteral()

実際に注入したいのは、メソッドによって返される文字列<http://www.codeproject.com/KB/recipes/n3_notation#foo>である URI のようです。そして、宣言を使用してこれを圧縮しようとしています。food1.send()my:fooPREFIX

したがって、URI を挿入したい場合は、代わりにSetUri()直接使用できます。

// Start a new query string
SparqlParameterizedString queryString = new SparqlParameterizedString();

// Set the desired prefix declarations
queryString.Namespaces.AddNamespace("my", new Uri("http://www.codeproject.com/KB/recipes/n3_notation#"));

// Set the command template
queryString.CommandText = @"SELECT ?name WHERE 
{ 
  [ a my:spec ; 
    my:preferedby @variable ;  
    my:name ?name ].  
}";

// Set your parameter
queryString.SetUri("variable", new Uri("http://www.codeproject.com/KB/recipes/n3_notation#" + preference));
于 2015-06-02T08:34:09.957 に答える