c# - .NET 中的 OpenCalais 解析 RDF

标签 c# .net rdf dotnetrdf opencalais

有没有一种方法可以在 .NET 中解析 OpenCalais RDF,因为我正在使用 dotnetRDF,它一直给我错误。生成的 Rdf 样本可以在 http://viewer.opencalais.com/ 中找到。 ,老实说,我真的迷路了,非常感谢任何帮助!如果您使用任何其他 api 或知道如何使其与 dotnetRDF 一起工作,请提供帮助,因为我真的真的迷路了

埃里卡

<!--Use of the Calais Web Service is governed by the Terms of Service located at http://www.opencalais.com. By using this service or the results of the service you agree to these terms of service.--><!--Relations: PersonEmailAddress

EmailAddress: jack@ctu.net, r.good@testings.com
Person: Jack Bauer, Rose Goodings--><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:c="http://s.opencalais.com/1/pred/"><rdf:Description c:allowDistribution="true" c:allowSearch="true" c:calaisRequestID="5e2f7759-55cb-ac2f-1281-b19ee8118cd9" c:externalID="calaisbridge" c:id="http://id.opencalais.com/KQGwCnWZBLPTHadX7uDMfA" rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/DocInfo"/><c:document><![CDATA[Jack Bauer <jack@ctu.net>
Rose Goodings <r.good@testings.com>]]></c:document><c:docTitle/><c:docDate>2010-04-20 07:03:23.998</c:docDate><c:externalMetadata c:caller="calaisbridge"/><c:submitter>calaisbridge</c:submitter></rdf:Description><rdf:Description c:contentType="text/raw" c:emVer="7.1.1103.5" c:langIdVer="DefaultLangId" c:language="InputTextTooShort" c:processingVer="CalaisJob01" c:submissionDate="2010-04-20 07:03:23.905" rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/meta"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/DocInfoMeta"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:submitterCode>416dcd8a-766f-0aa3-d94c-e5034b6ffc98</c:submitterCode><c:signature>digestalg-1|Kjq/y7thehi10hbBQ5v42YxE8n0=|a2DMjGG4mKEGTlIvvCvOg+BG1sCDrMZFSfRBjOBXMHwGtfLknC1nAQ==</c:signature></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/lid/DefaultLangId"><rdf:type rdf:resource="http://s.opencalais.com/1/type/lid/DefaultLangId"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:lang rdf:resource="http://d.opencalais.com/lid/DefaultLangId/InputTextTooShort"/></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/pershash-1/a3100b92-7d3d-3f63-afcb-265678c15dcc"><rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Person"/><c:name>Jack Bauer</c:name><c:persontype>N/A</c:persontype><c:nationality>N/A</c:nationality><c:commonname>Jack Bauer</c:commonname></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Instance/1"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/pershash-1/a3100b92-7d3d-3f63-afcb-265678c15dcc"/><!--Person: Jack Bauer; --><c:detection>[]Jack Bauer[ &lt;jack@ctu.net&gt;
Rose Goodings]</c:detection><c:prefix/><c:exact>Jack Bauer</c:exact><c:suffix> &lt;jack@ctu.net&gt;
Rose Goodings</c:suffix><c:offset>0</c:offset><c:length>10</c:length></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Relevance/1"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/RelevanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/pershash-1/a3100b92-7d3d-3f63-afcb-265678c15dcc"/><c:relevance>0.643</c:relevance></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/genericHasher-1/b323806b-4832-375a-aec8-56343d47e2d2"><rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/EmailAddress"/><c:name>r.good@testings.com</c:name></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Instance/2"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/genericHasher-1/b323806b-4832-375a-aec8-56343d47e2d2"/><!--EmailAddress: r.good@testings.com; --><c:detection>[Bauer &lt;jack@ctu.net&gt;
Rose Goodings &lt;]r.good@testings.com[&gt;]</c:detection><c:prefix>Bauer &lt;jack@ctu.net&gt;
Rose Goodings &lt;</c:prefix><c:exact>r.good@testings.com</c:exact><c:suffix>&gt;</c:suffix><c:offset>41</c:offset><c:length>19</c:length></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Relevance/2"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/RelevanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/genericHasher-1/b323806b-4832-375a-aec8-56343d47e2d2"/><c:relevance>0.643</c:relevance></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/genericHasher-1/addbee66-556c-3a3a-b2d4-4c4c1e668261"><rdf:type rdf:resource="http://s.opencalais.com/1/type/em/r/PersonEmailAddress"/><!--Rose Goodings--><c:person rdf:resource="http://d.opencalais.com/pershash-1/9f7b3610-9b76-34d4-8eea-3c2c0acbb31b"/><!--r.good@testings.com--><c:emailaddress rdf:resource="http://d.opencalais.com/genericHasher-1/b323806b-4832-375a-aec8-56343d47e2d2"/></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Instance/3"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/genericHasher-1/addbee66-556c-3a3a-b2d4-4c4c1e668261"/><!--PersonEmailAddress: person: Rose Goodings; emailaddress: r.good@testings.com; --><c:detection>[Bauer &lt;jack@ctu.net&gt;
]Rose Goodings &lt;r.good@testings.com[&gt;]</c:detection><c:prefix>Bauer &lt;jack@ctu.net&gt;
</c:prefix><c:exact>Rose Goodings &lt;r.good@testings.com</c:exact><c:suffix>&gt;</c:suffix><c:offset>26</c:offset><c:length>34</c:length></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/pershash-1/9f7b3610-9b76-34d4-8eea-3c2c0acbb31b"><rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/Person"/><c:name>Rose Goodings</c:name><c:persontype>N/A</c:persontype><c:nationality>N/A</c:nationality><c:commonname>Rose Goodings</c:commonname></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Instance/4"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/pershash-1/9f7b3610-9b76-34d4-8eea-3c2c0acbb31b"/><!--Person: Rose Goodings; --><c:detection>[Bauer &lt;jack@ctu.net&gt;
]Rose Goodings[ &lt;r.good@testings.com&gt;]</c:detection><c:prefix>Bauer &lt;jack@ctu.net&gt;
</c:prefix><c:exact>Rose Goodings</c:exact><c:suffix> &lt;r.good@testings.com&gt;</c:suffix><c:offset>26</c:offset><c:length>13</c:length></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Relevance/3"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/RelevanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/pershash-1/9f7b3610-9b76-34d4-8eea-3c2c0acbb31b"/><c:relevance>0.643</c:relevance></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/genericHasher-1/8c80538c-84d5-3394-a452-81a59a5eb11a"><rdf:type rdf:resource="http://s.opencalais.com/1/type/em/e/EmailAddress"/><c:name>jack@ctu.net</c:name></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Instance/5"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/genericHasher-1/8c80538c-84d5-3394-a452-81a59a5eb11a"/><!--EmailAddress: jack@ctu.net; --><c:detection>[Jack Bauer &lt;]jack@ctu.net[&gt;
Rose Goodings &lt;r.good@testings.com&gt;]</c:detection><c:prefix>Jack Bauer &lt;</c:prefix><c:exact>jack@ctu.net</c:exact><c:suffix>&gt;
Rose Goodings &lt;r.good@testings.com&gt;</c:suffix><c:offset>12</c:offset><c:length>12</c:length></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Relevance/4"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/RelevanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/genericHasher-1/8c80538c-84d5-3394-a452-81a59a5eb11a"/><c:relevance>0.643</c:relevance></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/genericHasher-1/a7bd9537-999f-3821-8858-c57f10ecd18d"><rdf:type rdf:resource="http://s.opencalais.com/1/type/em/r/PersonEmailAddress"/><!--Jack Bauer--><c:person rdf:resource="http://d.opencalais.com/pershash-1/a3100b92-7d3d-3f63-afcb-265678c15dcc"/><!--jack@ctu.net--><c:emailaddress rdf:resource="http://d.opencalais.com/genericHasher-1/8c80538c-84d5-3394-a452-81a59a5eb11a"/></rdf:Description><rdf:Description rdf:about="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902/Instance/6"><rdf:type rdf:resource="http://s.opencalais.com/1/type/sys/InstanceInfo"/><c:docId rdf:resource="http://d.opencalais.com/dochash-1/e7b46664-fa0c-3da1-88f9-cb79fe0d6902"/><c:subject rdf:resource="http://d.opencalais.com/genericHasher-1/a7bd9537-999f-3821-8858-c57f10ecd18d"/><!--PersonEmailAddress: person: Jack Bauer; emailaddress: jack@ctu.net; --><c:detection>[]Jack Bauer &lt;jack@ctu.net[&gt;
Rose Goodings &lt;r.good@testings.com&gt;]</c:detection><c:prefix/><c:exact>Jack Bauer &lt;jack@ctu.net</c:exact><c:suffix>&gt;
Rose Goodings &lt;r.good@testings.com&gt;</c:suffix><c:offset>0</c:offset><c:length>24</c:length></rdf:Description></rdf:RDF>

我还有以下内容(文件中包含上述文本):

        System.IO.StreamReader tr = new System.IO.StreamReader("C:/test.txt");
        string s = tr.ReadToEnd();

        Graph g = new Graph();
        FileLoader.Load(g, "C:/test.txt");

我得到以下异常 RDFParseException

StringParser 未能正确解析 RDF 字符串,StringParser 自动检测猜测为“NTriples”,但这未能解析。 RDF 字符串可能格式不正确或 StringParser 可能猜错了

我真的迷路了,请帮忙

最佳答案

正确的错误与 RDF/XML 解析器有关,在某些情况下不能正确处理 CDATA 元素,现在应该修复这个问题,我已经上传了新版本的库,修复了这个错误 dotnetrdf.org和 SourceForge

如果您再次下载它并在 OpenCalais 的 RDF 上尝试它,它现在应该可以正常工作(我希望)

我尝试尽快修复错误并支持我的用户,所以如果您有任何其他问题,请在邮件列表中告诉我,以便我尽快看到并解决您的问题:

dotnetrdf-bugs@lists.sourceforge.net
dotnetrdf-develop@lists.sourceforge.net

编辑

对于您的示例应用程序,StringParser 无法正确检测数据格式,因为没有 <?xml version="1.0"?>对 RDF/XML 期望的声明

尝试以下方法来显式设置要使用的解析器:

FileLoader.Load(g, "C:\test.txt", new RdfXmlParser());

或者将文件重命名为 test.rdf在这种情况下,in 将从文件扩展名猜测数据格式为 RDF/XML,而不必通过读取文件并对原始字符串执行一些简单的正则表达式来猜测

关于c# - .NET 中的 OpenCalais 解析 RDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2671325/

相关文章:

c# - INotifyPropertyChanged 与线程

c# - 简单 float 计算错误

c# - 如何从 ViewModel 中的 ComboBox 中获取值

c# - 在 C# 中执行 CMD 打开远程桌面

c# - 在与 Ninject 绑定(bind)时使用通用类型——这可能吗?

rdf - 大约="#this"的目的-

SPARQL 将 MAX 应用于聚合值

c# - 不同地区不同认证方式

c# - 创建一个列表,其中元素计数与另一个列表相关

rdf - 我可以暂时暂停 RDF 批量加载过程一段时间,然后将其恢复正常吗?