【问题标题】:Extracting information from DBpedia从 DBpedia 中提取信息
【发布时间】:2013-09-18 16:11:03
【问题描述】:

我正在做一个项目,我想使用 DBpedia。我有数百个 DBpedia 链接,例如

什么是更好地利用时间:

  • 抓取这些页面并提取我想要的信息?
  • 使用 Python 中的 SPARQL 查询来查询数据?

【问题讨论】:

    标签: python sparql semantic-web dbpedia


    【解决方案1】:

    首先,请注意标识 DBpedia 资源的 URI 不是

    页面,但是

    资源。其次,使用 SPARQL 检索信息会快得多。 SPARQL 是一种用于 RDF 的查询语言,您正在寻找 RDF 数据。在 SPARQL 中获取有关 FEMA 的信息所需要做的就是一个 describe 查询:

    describe
      dbpedia:Federal_Emergency_Management_Agency
    

    SPARQL results

    Describe 查询可以描述多个资源,因此您可以这样做,例如:

    describe
      dbpedia:Federal_Emergency_Management_Agency
      dbpedia:Mount_Monadnock
      # more resources...
    

    SPARQL results

    如果您只想要某些资源的某些信息,您仍然可以使用选择或构造查询执行类似的操作,使用 values 并以编程方式注入您感兴趣的资源:

    select ?label where { 
      values ?resource {
        dbpedia:Federal_Emergency_Management_Agency # put your values in here and
        dbpedia:Mount_Monadnock                     # ?resource will be bound to each
      }
      ?resource rdfs:label ?label .
      filter( langMatches( lang(?label), "EN" ))
    }
    

    SPARQL results

    您还可以使用构造在模型中获取这些三元组:

    construct {
      ?resource rdfs:label ?label 
    }
    where { 
      values ?resource {
        dbpedia:Federal_Emergency_Management_Agency
        dbpedia:Mount_Monadnock
      }
      ?resource rdfs:label ?label .
      filter( langMatches( lang(?label), "EN" ))
    }
    

    SPARQL results

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 2012-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多