【问题标题】:Insert a RDF data to Virtuoso by using dotNetRDF library in C# .Net在 C# .Net 中使用 dotNetRDF 库将 RDF 数据插入 Virtuoso
【发布时间】:2016-10-13 16:07:50
【问题描述】:

我想知道如何使用 dotNetRDF 将 RDF(下载这样的字符串)插入 Virtuoso。

例如,我已经阅读了您在此链接上找到的 RDF 数据:“http://publications.europa.eu/resource/cellar/fdc34ca7-6cbf-4f81-8bbd-e7255ccfa0c2.0005/rdf/object/full

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://publications.europa.eu/ontology/cdm#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:j.1="http://www.w3.org/2004/02/skos/core#"
    xmlns:j.2="http://publications.europa.eu/ontology/annotation#"
    xmlns:j.3="http://publications.europa.eu/ontology/cdm/cmr#" > 
  <rdf:Description rdf:about="http://publications.europa.eu/resource/cellar/fdc34ca7-6cbf-4f81-8bbd-e7255ccfa0c2.0005.02">
    <owl:sameAs rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA.print"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://publications.europa.eu/resource/cellar/fdc34ca7-6cbf-4f81-8bbd-e7255ccfa0c2.0005">
    <j.3:metsStructSuperDiv rdf:resource="http://publications.europa.eu/resource/cellar/fdc34ca7-6cbf-4f81-8bbd-e7255ccfa0c2"/>
    <j.3:lang rdf:datatype="http://www.w3.org/2001/XMLSchema#language">fr</j.3:lang>
    <j.3:lang rdf:datatype="http://www.w3.org/2001/XMLSchema#language">fra</j.3:lang>
    <owl:sameAs rdf:resource="http://publications.europa.eu/resource/celex/31998R2278.FRA"/>
    <owl:sameAs rdf:resource="http://publications.europa.eu/resource/uriserv/OJ.L_.1998.286.01.0013.01.FRA"/>
    <owl:sameAs rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA"/>
    <j.3:lastModificationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2014-04-04T10:21:30.312+02:00</j.3:lastModificationDate>
  </rdf:Description>
  <rdf:Description rdf:about="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA">
    <j.0:uses rdf:resource="http://publications.europa.eu/resource/authority/language/FRA"/>
    <j.0:expression_title_information_additional rdf:datatype="http://www.w3.org/2001/XMLSchema#string">CELEX1</j.0:expression_title_information_additional>
    <j.0:title rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Règlement (CE) n° 2278/98 de la Commission du 22 octobre 1998 déterminant la mesure dans laquelle les demandes de certificats d'importation introduites en octobre 1998 pour certains produits du secteur de la viande de porc peuvent être acceptées dans le cadre du régime prévu par le règlement (CE) n° 774/94 du Conseil portant ouverture et mode de gestion de certains contingents tarifaires communautaires pour la viande porcine et certains autres produits agricoles</j.0:title>
    <j.0:title_information_additional rdf:datatype="http://www.w3.org/2001/XMLSchema#string">CELEX1</j.0:title_information_additional>
    <j.0:expression_belongs_to_work rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007"/>
    <j.0:title rdf:datatype="http://www.w3.org/2001/XMLSchema#string">CELEX1</j.0:title>
    <j.0:expression_manifested_by_manifestation rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA.print"/>
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#expression"/>
    <j.0:expression_title rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Règlement (CE) n° 2278/98 de la Commission du 22 octobre 1998 déterminant la mesure dans laquelle les demandes de certificats d'importation introduites en octobre 1998 pour certains produits du secteur de la viande de porc peuvent être acceptées dans le cadre du régime prévu par le règlement (CE) n° 774/94 du Conseil portant ouverture et mode de gestion de certains contingents tarifaires communautaires pour la viande porcine et certains autres produits agricoles</j.0:expression_title>
    <j.0:expression_uses_language rdf:resource="http://publications.europa.eu/resource/authority/language/FRA"/>
    <j.2:build_info>cdm:CDM_2.1.7  tdm:1523  xslt:3945 saxon:9.0.0.1J JVM:1.6.0_29 metaconvJar:1.2.0 builddate:04/04/2014 01:00:03</j.2:build_info>
    <j.0:expression_manifested_by_manifestation rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA.pdf"/>
    <j.0:belongs_to rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007">
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#legislation_secondary"/>
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#work"/>
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#resource_legal"/>
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#regulation"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://publications.europa.eu/resource/authority/language/FRA">
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#language"/>
    <rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
    <j.1:inScheme rdf:resource="http://publications.europa.eu/resource/authority/language"/>
    <j.0:language_used_by_expression rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA.pdf">
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#manifestation"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://publications.europa.eu/resource/cellar/fdc34ca7-6cbf-4f81-8bbd-e7255ccfa0c2">
    <owl:sameAs rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007"/>
    <owl:sameAs rdf:resource="http://publications.europa.eu/resource/eli/reg/1998/2278/oj"/>
    <owl:sameAs rdf:resource="http://publications.europa.eu/resource/celex/31998R2278"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA.print">
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#manifestation_official-journal_part"/>
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#manifestation"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://publications.europa.eu/resource/cellar/fdc34ca7-6cbf-4f81-8bbd-e7255ccfa0c2.0005.01">
    <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#manifestation"/>
    <owl:sameAs rdf:resource="http://publications.europa.eu/resource/oj/JOL_1998_286_R_0013_007.FRA.pdf"/>
  </rdf:Description>
</rdf:RDF>

我已经将它(通过使用 HttpWebRequest)存储在一个字符串中,但我不知道如何通过 dotNetRDF 将它插入到我的 Virtuoso 中。任何的想法?

另外,如何在QueryWithResultSet函数上设置UserAgent呢? 在这个 EndPoint 上:http://publications.europa.eu/webapi/rdf/sparql 我必须设置 UserAgent,否则我无法从中获取查询。

谢谢

PS:我无法直接从目标服务器加载 RDF,因为出现 502 Bad Gateway 错误。

【问题讨论】:

  • 1.我不想编写 RDF 并保存在另一个文件或流中 2。我想将数据保存到现有图表,我不需要保存图表! 3. 这是我在 Virtuoso 的第三个项目,当然我知道 Virtuoso 以及如何通过 dotNetRDF 连接到它。 4. 无法将在线RDF直接写入服务器,因为dotNetRDF库中缺少UserAgent设置。
  • @TallTed 你有别的想法吗? virtuoso.UpdateGraph("example.org/graph", null, new Triple[] { t });可以帮助我,但我不知道如何将 RDF 字符串转换为 Triple 数组!
  • 如果您需要自定义HttpWebRequest,例如添加UserAgent 标头,您可以扩展SparqlRemoteEndpoint 并覆盖ApplyCustomRequestOptions() 方法。
  • 真的没那么难,加了一个答案来证明这一点

标签: .net rdf virtuoso triplestore dotnetrdf


【解决方案1】:

如果您需要自定义HttpWebRequest,例如添加UserAgent 标头,您可以扩展SparqlRemoteEndpoint 并覆盖ApplyCustomRequestOptions() 方法:

public class MyCustomEndpoint : SparqlRemoteEndpoint
{
  // Define appropriate constructors with the parameters you need e.g.
  public MyCustomEndpoint(Uri endpointUri)
    : base(endpointUri) { }     

  protected override ApplyCustomRequestOptions(HttpWebRequest request)
  {
     request.UserAgent = "My Custom User Agent"
  } 
}

ApplyCustomRequestOptions() 方法在每个 HttpWebRequest 提交之前被调用,因此可用于进行任何需要的自定义。然后只需根据需要使用MyCustomEndpoint 代替SparqlRemoteEndpoint

您可以随时参考SparqlRemoteEndpoint 文档以获取有关可用方法和属性的更多详细信息。

【讨论】:

  • 总是有问题 502 BadGateway。我认为这与我的查询无关,他们已经添加了一个 Firwall 来进行查询。
  • 有没有办法通过c#语法用ISQL工作区替换导入数据?
  • 如果您有不同的问题,那么您应该创建一个新问题!评论仅用于澄清问题/答案
  • 如何在 dotNetRDF 中调试 HTTP 通信 - github.com/dotnetrdf/dotnetrdf/wiki/…
  • 我已经用“在 dotNetRDF 中调试 HTTP 通信”进行了测试,我收到一条错误消息,告诉我他们阻止我访问此服务。我想知道他们如何阻止这项服务?它是一项特定的服务吗?我怎样才能在我的演奏家上做同样的事情?端点为:publications.europa.eu/webapi/rdf/sparql
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多