1

dotNetRDFを使用して、次のクエリをDBpediaに送信しようとしています。

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX temp: <http://www.example.com/temp/>

CONSTRUCT {
  ?v1 a temp:r.
  ?v1 temp:p0 ?v2.
}
WHERE {
  OPTIONAL {
    {
      {
        SELECT ?v1
        WHERE {
          ?v1 rdfs:comment ?v2.
        }
        LIMIT 10
      }.
      ?v1 rdfs:comment ?v2.
    }.
  }.
}

しかし、RdfParseException予期しないr文字が見つかったとのことです (114 は の 10 進文字コードですr)。

同じクエリに対してWeb ベースの DBpedia SPARQL フォームを使用すると、妥当と思われる結果が返されます。したがって、私の SPARQL クエリに問題はないと思います。少なくとも、DBpedia が対処できなかった問題はありません。

とを有効にして、同様の問題についてこの質問からのアドバイスに従おうとしました。その質問に対する受け入れられた回答で説明されているように、これは受信した応答を stderr に出力します。ただし、「別のエラー」は発生しません。代わりに、クエリは成功したように見えますが、返されたグラフは空です (トリプルが含まれていません)。Options.HttpDebuggingOptions.HttpFullDebugging

問題を再現する最小限のサンプルを次に示します。

using System;
using System.Runtime.ConstrainedExecution;

using VDS.RDF;
using VDS.RDF.Query;
using VDS.RDF.Writing;

namespace DotNetRdfParsingError
{
    class Program
    {
        public static void Main(string[] args)
        {
            var endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"));

            string query =
                "PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
                "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
                "PREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>\n" +
                "PREFIX temp: <http://www.example.com/temp/>\n" +
                "\n" +
                "CONSTRUCT {\n" +
                "  ?v1 a temp:r.\n" +
                "  ?v1 temp:p0 ?v2.\n" +
                "}\n" +
                "WHERE {\n" +
                "  OPTIONAL {\n" +
                "    {\n" +
                "      {\n" +
                "        SELECT ?v1\n" +
                "        WHERE {\n" +
                "          ?v1 rdfs:comment ?v2.\n" +
                "        }\n" +
                "        LIMIT 10\n" +
                "      }.\n" +
                "      ?v1 rdfs:comment ?v2.\n" +
                "    }.\n" +
                "  }.\n" +
                "}";

            Console.WriteLine("Without HTTP debugging:");
            try {
                var graph = endpoint.QueryWithResultGraph(query);
                PrintGraph(graph);
            }
            catch (Exception ex) {
                Console.WriteLine("EXCEPTION:\n" + ex.ToString());
            }

            Console.WriteLine("With HTTP debugging:");
            try {
                Options.HttpDebugging = true;
                Options.HttpFullDebugging = true;
                var graph = endpoint.QueryWithResultGraph(query);
                PrintGraph(graph);
            }
            catch (Exception ex) {
                Console.WriteLine("EXCEPTION:\n" + ex.ToString());
            }
        }

        private static void PrintGraph(IGraph graph)
        {
            if (graph != null) {
                using (var stringWriter = new System.IO.StringWriter()) {
                    var turtleWriter = new TurtleWriter();
                    turtleWriter.PrettyPrintMode = true;
                    turtleWriter.Save(graph, stringWriter);
                    Console.WriteLine("Graph:\n\n" + stringWriter.ToString() + "\n");
                }
            } else {
                Console.WriteLine("Graph is null.");
            }
        }
    }
}

これにより、次の出力が生成されます。

Without HTTP debugging:
EXCEPTION:
VDS.RDF.Parsing.RdfParseException: [Line 1 Column 9] Unexpected Character (Code 114) r was encountered
   bei VDS.RDF.Parsing.Tokens.NTriplesTokeniser.GetNextToken()
   bei VDS.RDF.Parsing.Tokens.BufferedTokenQueue.BufferInternal()
   bei VDS.RDF.Parsing.Tokens.BufferedTokenQueue.InitialiseBuffer(Int32 amount)
   bei VDS.RDF.Parsing.NTriplesParser.Parse(TokenisingParserContext context)
   bei VDS.RDF.Parsing.NTriplesParser.Load(IRdfHandler handler, TextReader input)
   bei VDS.RDF.Parsing.NTriplesParser.Load(IRdfHandler handler, StreamReader input)
   bei VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultGraph(IRdfHandler handler, String sparqlQuery)
   bei VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultGraph(String sparqlQuery)
   bei DotNetRdfParsingError.Program.Main(String[] args) in c:\Users\uname\Documents\Test\DOTNET\DotNetRdfParsingError\DotNetRdfParsingError\Program.cs:Zeile 43.
With HTTP debugging:
# HTTP DEBUGGING #
HTTP Request to http://dbpedia.org/sparql?query=PREFIX%20rdf%3A%20%20%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX%20xsd%3A%20%20%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%3E%0APREFIX%20temp%3A%20%3Chttp%3A%2F%2Fwww.example.com%2Ftemp%2F%3E%0A%0ACONSTRUCT%20%7B%0A%20%20%3Fv1%20a%20temp%3Ar.%0A%20%20%3Fv1%20temp%3Ap0%20%3Fv2.%0A%7D%0AWHERE%20%7B%0A%20%20OPTIONAL%20%7B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20SELECT%20%3Fv1%0A%20%20%20%20%20%20%20%20WHERE%20%7B%0A%20%20%20%20%20%20%20%20%20%20%3Fv1%20rdfs%3Acomment%20%3Fv2.%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20LIMIT%2010%0A%20%20%20%20%20%20%7D.%0A%20%20%20%20%20%20%3Fv1%20rdfs%3Acomment%20%3Fv2.%0A%20%20%20%20%7D.%0A%20%20%7D.%0A%7D

GET
Accept:text/plain,text/ntriples,text/ntriples+turtle,application/rdf-triples,application/x-ntriples,text/plain,text/ntriples,text/ntriples+turtle,application/rdf-triples,application/x-ntriples,text/turtle,application/x-turtle,application/turtle,text/turtle,application/x-turtle,application/turtle,text/n3,text/rdf+n3,text/n3,text/rdf+n3,application/rdf+xml,text/xml,application/xml,application/rdf+xml,text/xml,application/xml,application/json,text/json,application/rdf+json,application/json,text/json,application/rdf+json,text/html,application/xhtml+xml,text/html,application/xhtml+xml,*/*;q=0.5


HTTP Response from http://dbpedia.org/sparql?query=PREFIX%20rdf%3A%20%20%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX%20xsd%3A%20%20%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%3E%0APREFIX%20temp%3A%20%3Chttp%3A%2F%2Fwww.example.com%2Ftemp%2F%3E%0A%0ACONSTRUCT%20%7B%0A%20%20%3Fv1%20a%20temp%3Ar.%0A%20%20%3Fv1%20temp%3Ap0%20%3Fv2.%0A%7D%0AWHERE%20%7B%0A%20%20OPTIONAL%20%7B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20SELECT%20%3Fv1%0A%20%20%20%20%20%20%20%20WHERE%20%7B%0A%20%20%20%20%20%20%20%20%20%20%3Fv1%20rdfs%3Acomment%20%3Fv2.%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20LIMIT%2010%0A%20%20%20%20%20%20%7D.%0A%20%20%20%20%20%20%3Fv1%20rdfs%3Acomment%20%3Fv2.%0A%20%20%20%20%7D.%0A%20%20%7D.%0A%7D
HTTP/1.1 200 OK

Connection:keep-alive
Vary:Accept-Encoding
Accept-Ranges:bytes
Content-Length:5451
Content-Type:text/plain
Date:Fri, 18 Oct 2013 08:06:33 GMT
Server:Virtuoso/07.00.3204 (Linux) i686-generic-linux-glibc212-64  VDB

@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ns1:    <http://www.example.com/temp/> .
<http://dbpedia.org/resource/American_Legion_Field_(Florence)>  rdf:type    ns1:r ;
    ns1:p0  "American Legion Field is a baseball venue in Florence, South Carolina, USA. It is home to the Florence Red Wolves of the Coastal Plain League, a collegiate summer baseball league. The Red Wolves have played at the field since 1998. The venue was built sometime before 1981 and has a capacity of 3,500. The field's dimensions are 305 ft. down the foul lines, 335 ft. to the gaps, and 385 ft. to dead center field."@en .
@prefix dbpedia:    <http://dbpedia.org/resource/> .
dbpedia:Francisco_Bautista  rdf:type    ns1:r ;
    ns1:p0  "Francisco Bautista Cuamatzi is a male long-distance runner from Mexico. He represented his native country at the 2008 Summer Olympics in Beijing, PR China, where he finished in 66th place in the men's marathon event, clocking 2:29.28. Rojas set his personal best in the marathon on March 7, 2004 in Torre\u00F3n."@en ,
        "Francisco Bautista ist ein mexikanischer Marathonl\u00E4ufer. Bei den Halbmarathon-Weltmeisterschaften 1999 in Palermo kam er auf den 87. Platz. Im Jahr darauf wurde er F\u00FCnfter beim Marat\u00F3n de la Comarca Lagunera und Achter beim Mailand-Marathon. 2001 wurde er Sechster in der Comarca Lagunera, Zentralamerika/Karibik-Vizemeister im Halbmarathon, belegte bei den Leichtathletik-Weltmeisterschaften in Edmonton Rang 66 und gewann den Monterrey-Marathon."@de .
<http://dbpedia.org/resource/Tillandsia_\u0027Comet\u0027>  rdf:type    ns1:r ;
    ns1:p0  "'Comet' is a hybrid cultivar of the genus Tillandsia in the Bromeliad family."@en .
dbpedia:Glass_Sky   rdf:type    ns1:r ;
    ns1:p0  "Glass Sky is a Japanese manga anthology written and illustrated by Yugi Yamada. It is licensed in North America by Digital Manga Publishing, which released the manga through its June imprint, on December 12, 2007."@en .
dbpedia:Healthcare_in_Guntur    rdf:type    ns1:r ;
    ns1:p0  "The region of Guntur has many health care facilities supported by both the government and private institutions. It is one of the major cities on the east coast region of India in providing excellent medical and health care facilities."@en .
dbpedia:Lake_Nuijamaa   rdf:type    ns1:r ;
    ns1:p0  "Lake Nuijamaa is a lake on the border between Finland and Russia next to the town of Nuijamaa. It is part of the Saimaa Canal linking Vyborg Bay in the Baltic Sea to Lake Saimaa in the Finnish Lakeland."@en ,
        "\u041D\u0443\u0439\u044F\u043C\u0430\u044F\u0440\u0432\u0438\u00A0\u2014 \u043E\u0437\u0435\u0440\u043E \u043D\u0430 \u041A\u0430\u0440\u0435\u043B\u044C\u0441\u043A\u043E\u043C \u043F\u0435\u0440\u0435\u0448\u0435\u0439\u043A\u0435 \u043D\u0430 \u0433\u0440\u0430\u043D\u0438\u0446\u0435 \u0424\u0438\u043D\u043B\u044F\u043D\u0434\u0438\u0438 \u0438 \u0420\u043E\u0441\u0441\u0438\u0438. \u041E\u0437\u0435\u0440\u043E \u0440\u0430\u0441\u043F\u043E\u043B\u043E\u0436\u0435\u043D\u043E \u0432 20 \u043A\u043C \u043D\u0430 \u044E\u0433\u043E-\u0432\u043E\u0441\u0442\u043E\u043A \u043E\u0442 \u0444\u0438\u043D\u0441\u043A\u043E\u0433\u043E \u0433\u043E\u0440\u043E\u0434\u0430 \u041B\u0430\u043F\u043F\u0435\u044D\u043D\u0440\u0430\u043D\u0442\u0430 \u0438 \u0432 26\u00A0\u043A\u043C \u043D\u0430 \u0441\u0435\u0432\u0435\u0440\u043E-\u0437\u0430\u043F\u0430\u0434 \u043E\u0442 \u0440\u043E\u0441\u0441\u0438\u0439\u0441\u043A\u043E\u0433\u043E \u0412\u044B\u0431\u043E\u0440\u0433\u0430. \u0427\u0435\u0440\u0435\u0437 \u043D\u0435\u0433\u043E \u043F\u0440\u043E\u0445\u043E\u0434\u0438\u0442 \u0421\u0430\u0439\u043C\u0435\u043D\u0441\u043A\u0438\u0439 \u043A\u0430\u043D\u0430\u043B."@ru .
dbpedia:Michelangelo_Unterberger    rdf:type    ns1:r ;
    ns1:p0  "Michelangelo Unterberger (August 11, 1695 \u2013 June 27, 1758), was an Austrian painter. Unterberger was born at Cavalese, in what was then Austrian Tyrol, and was part of an Austrian family of artists. He was originally taught by Giuseppe Alberti, and painted primarily religious-themed works."@en ,
        "Michelangelo Unterberger, auch Michael Angelo Unterberger und Michelangelo Unterperger war ein S\u00FCdtiroler Maler des Barock."@de ,
        "Michelangelo Unterberger, aussi Michael Angelo Unterberger ou Michelangelo Unterperger est un peintre autrichien, originaire de la province autonome de Bolzano, et de l'\u00E9poque baroque."@fr .
<http://dbpedia.org/resource/Miroslav_Ivani%C5%A1evi%C4%87> rdf:type    ns1:r ;
    ns1:p0  "Miroslav Ivani\u0161evi\u0107 is a Montenegrin politician. He was appointed as the Montenegrin Minister of Finance in 1998. In 2007 he was accused of being involved in cigarette smuggling into Italy, but was found not guilty in 2010."@en .
dbpedia:Skin_for_Skin   rdf:type    ns1:r ;
    ns1:p0  "Skin for Skin \u00E8 per ora l'ultimo album pubblicato dalla heavy/christian metal band Bride, nel 2006."@it ,
        "Skin for Skin \u00E9 um \u00E1lbum da banda de heavy metal Bride, lan\u00E7ado em 2006 pela gravadora Retrospective Records. A banda sai de seu estilo alternativo e lan\u00E7a um [disco extremamente pesado e totalmente heavy metal.]"@pt ,
        "Skin for Skinis the twelfth studio album by the rock band Bride."@en .
<http://dbpedia.org/resource/Union_Church_(Buckfield,_Maine)>   rdf:type    ns1:r ;
    ns1:p0  "Union Church is a historic church off ME 140 in Buckfield, Maine. It was built in 1832 and added to the National Register of Historic Places in 1980."@en .

# END HTTP DEBUGGING #
Graph:

@base <http://dbpedia.org/sparql>.

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.

そこに見られるように、結果のグラフはいくつかのプレフィックスのみで構成されていますが、ノードやトリプルは含まれていません。

例外は、結果のグラフの行 1、列 9 を指します。これは、受信した応答を見るとrdf、プレフィックス宣言のプレフィックスの始まりになります。

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

私が独特だと思うことの 1 つは、例外がNTriplesTokeniser内のどこかによってスローされることですが、返されたグラフはN-TriplesではなくTurtleNTriplesParserのように見えます。

NuGet の最新の dotNetRDF バージョン、現在 1.0.1.2809を使用しています。

私はそこで何か間違ったことをしていますか、またはこの場合に必要な dotNetRDF の追加設定はありますか?

編集:完全を期すために、内部にいくつかのDBpediaデータがあるローカルのVirtuosoインストールに追加する必要があります。クラッシュはありません。

4

1 に答える 1

4

はい、DBPedia が間違ったことをしているようです。何らかの理由で、Turtle の適切な値である ではなく、 Content-Typeofを使用して Turtle を返しています。したがって、dotNetRDF が NTriples パーサーを選択してから問題が発生するのはなぜですか。text/plainapplication/turtle

これを DBPedia の人々に報告して、この問題を解決できるかどうかを確認する価値があります。

dotNetRDF は、Acceptヘッダーの形成方法を改善text/plainしてリストの下位に配置できますが、それでも DBPedia がコンテンツ ネゴシエーションを正しく行っていないように見えるという事実は解決されません。

ドキュメントにあるように、プロパティを使用しRdfAcceptHeaderてこれを回避できます。

dotNetRDF がデフォルトで送信する広範な Accept ヘッダーを好まないバグのあるエンドポイントを回避するために使用できます。

例えば:

endpoint.RdfAcceptHeader = "application/turtle";

この回避策を使用すると、指定されたコードは例外をスローしません。

HTTPデバッグはさておき

別のエラーを引き起こす HTTP デバッグに関するポイントの最後にOptions.HttpFullDebugging、応答ストリームを消費するため、パーサーは既に最後にあるストリームを受け取ります。

パーサーによっては、これにより異なる解析エラーが発生する可能性がありますが、テキスト形式である NTriple の場合、空のストリームは有効な空のグラフのシリアル化です。GraphdotNetRDF のインスタンスには常にプレフィックスがありrdf、デフォルトrdfsxsd定義されているため、グラフにはたまたまいくつかのプレフィックスがあります。

于 2013-10-18T10:03:40.643 に答える