【问题标题】:How to get all nouns in a certain language from Wiktionary using SPARQL如何使用 SPARQL 从维基词典中获取某种语言的所有名词
【发布时间】:2015-06-17 15:26:46
【问题描述】:

我正在尝试使用 SPARQL 查询维基词典以获取所有属于某种语言名词的术语(例如德语) 并作为输出:

  • 名词的字符串
  • 语法性别(属):男、女、中性

我正在使用 SPARQL-Endpoint:http://wiktionary.dbpedia.org/sparql,我找到了一个示例,但我没有弄清楚 如何调整它以获得我想要的信息。

PREFIX terms:<http://wiktionary.dbpedia.org/terms/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX dc:<http://purl.org/dc/elements/1.1/>
SELECT ?sword ?slang ?spos ?ssense ?twordRes ?tword ?tlang
FROM <http://wiktionary.dbpedia.org>
WHERE {
    ?swordRes terms:hasTranslation ?twordRes .
    ?swordRes rdfs:label ?sword .
    ?swordRes dc:language ?slang .
    ?swordRes terms:hasPoS ?spos .
    OPTIONAL { ?swordRes terms:hasMeaning ?ssense . }
    OPTIONAL { 
           ?twordBaseRes terms:hasLangUsage ?twordRes . 
           ?twordBaseRes rdfs:label ?tword .
    }
    OPTIONAL { ?twordRes dc:language ?tlang . }
}

【问题讨论】:

    标签: sparql wiktionary


    【解决方案1】:

    首先,您要选择所有名词的词义。如您在示例查询的查询结果中所见,此信息由terms:hasPoS 关系捕获。因此,要专门查询所有名词,我们可以这样做:

    PREFIX terms: <http://wiktionary.dbpedia.org/terms/>
    SELECT ?term
    WHERE { 
         ?term terms:hasPoS terms:Noun . 
    }
    LIMIT 100 
    

    Result

    接下来你想要的只是某种语言的名词。这似乎被dc:language 关系所覆盖,因此我们在该关系上添加了一个额外的约束。假设我们想要所有英语名词:

    PREFIX terms: <http://wiktionary.dbpedia.org/terms/>
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
    
    SELECT ?term
    WHERE { 
        ?term terms:hasPoS terms:Noun ;
              dc:language terms:English . 
    }
    LIMIT 100 
    

    Result

    所以,我们现在正在选择您想要的内容,但我们还没有您想要的格式的输出,因为上面的查询只是返回术语含义的标识符,而不是实际的字符串值学期。正如我们在示例查询的输出中看到的那样,字符串值由rdfs:label 属性捕获,因此我们添加:

    PREFIX terms: <http://wiktionary.dbpedia.org/terms/>
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    
    SELECT ?term ?termLabel
    WHERE { 
        ?term terms:hasPoS terms:Noun ;
              dc:language terms:English ;
              rdfs:label ?termLabel .
    }
    LIMIT 100
    

    Result

    如果您现在查看此查询的结果,您会发现该语言存在一些奇怪的地方:尽管我们认为我们选择了英语,但我们也得到了具有不同语言标签的标签(例如'@ru')。要删除这些结果,我们可以进一步限制我们的查询,并说我们只想要英文标签:

    PREFIX terms: <http://wiktionary.dbpedia.org/terms/>
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
    PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
    
    SELECT ?term ?termLabel
    WHERE { 
        ?term terms:hasPoS terms:Noun ;
              dc:language terms:English ;
              rdfs:label ?termLabel .
        FILTER(langMatches(lang(?termLabel), "en"))
    }
    LIMIT 100
    

    Result

    最后,性别/属。在这里我不太确定。查看维基词典数据中的一些示例资源(例如,entry for dog)我想说这些信息实际上并不存在于数据中。

    【讨论】:

      【解决方案2】:

      Jeen 的回答是一个很好的开始。这是获取性别的选项。

      英语不适合作为示例语言,因为它没有语法性别。让我们以德语为例:

      PREFIX terms: <http://wiktionary.dbpedia.org/terms/>
      PREFIX dc: <http://purl.org/dc/elements/1.1/>
      PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
      
      SELECT ?term ?termLabel
      WHERE { 
          ?term terms:hasPoS terms:Noun ;
                dc:language terms:German ;
                rdfs:label ?termLabel .
          FILTER(langMatches(lang(?termLabel), "de"))
      }
      LIMIT 100
      

      Result

      (过滤许多精确的重复项会很好。(我不知道它们是如何存在的,以及它们为什么存在。)

      用德语“Eierkopf”代替英语“dog”: 我们现在可以按照链接到http://wiktionary.dbpedia.org/resource/Eierkopf-German-Noun 的术语来查看德语中的维基词典http://de.wiktionary.org/wiki/Eierkopf 的链接(我们也可以猜到该URL,而无需先从wiktionary.dbpedia.org 获取)。

      这里可以从文本中提取属:“Substantiv, m”(m代表阳性)

      德语的选项是:

      <em title="Genus: Maskulinum (grammatikalisches Geschlecht: männlich)">m</em>
      <em title="Genus: Femininum (grammatikal. Geschlecht: weiblich)">f</em>
      <em title="Genus: Neutrum (grammatikal. Geschlecht: sächlich)">n</em>
      

      如果名词根据地区/方言有不同的性别,则官方性别如上在 HTML 中,并在下方显示注释。示例:

      https://de.wiktionary.org/wiki/Butter

      所以除了查询 SPARQL 之外,它还需要每个单词 1-2 个网页请求,以及一些 HTML 内容提取。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-15
        • 1970-01-01
        • 2011-02-15
        相关资源
        最近更新 更多