programing

위키 낱말 사전 콘텐츠를 검색하는 방법?

nasanasas 2020. 9. 22. 08:16
반응형

위키 낱말 사전 콘텐츠를 검색하는 방법?


단어가 존재하는지 여부를 확인하기 위해 Wiktionary의 API를 어떻게 사용할 수 있습니까?


위키 낱말 사전 API는 단어가 존재하는지 여부를 질의하는 데 사용할 수 있습니다.

기존 및 존재하지 않는 페이지의 예 :

http://en.wiktionary.org/w/api.php?action=query&titles=test http://en.wiktionary.org/w/api.php?action=query&titles=testx

첫 번째 링크는 구문 분석이 더 쉬울 수있는 다른 형식의 예를 제공합니다.

작은 XHTML 형식 (필요한 것 이상이어야 함)으로 단어의 데이터를 검색하려면 페이지의 인쇄 가능한 버전을 요청하십시오.

http://en.wiktionary.org/w/index.php?title=test&printable=yes http://en.wiktionary.org/w/index.php?title=testx&printable=yes

그런 다음 표준 XML 파서로 구문 분석 할 수 있습니다.


위키 셔 너리에 찾고있는 이름의 페이지가 있는지 확인하는 데 몇 가지주의 사항이 있습니다.

주의 사항 # 1 : English Wiktionary를 포함한 모든 Wiktionary는 실제로 모든 언어의 모든 단어를 포함하는 목표를 가지고 있으므로 위의 API 호출을 사용하면 요청하는 단어가 적어도 하나의 언어로 된 단어라는 것을 알 수 있습니다. 반드시 영어는 아님 : http://en.wiktionary.org/w/api.php?action=query&titles=dicare

주의 사항 # 2 : 한 단어에서 다른 단어로 리디렉션이있을 수 있습니다. 대체 철자 일 수도 있지만 어떤 종류의 오류 일 수도 있습니다. 위의 API 호출은 리디렉션과 기사를 구분하지 않습니다. http://en.wiktionary.org/w/api.php?action=query&titles=profilemetry

주의 사항 # 3 : 영어 위키 낱말 사전을 포함한 일부 위키 낱말 사전에는 "일반적인 맞춤법 오류"가 포함됩니다. http://en.wiktionary.org/w/api.php?action=query&titles=fourty

주의 사항 # 4 : 일부 위키 낱말 사전은 용어에 대한 정보가 거의 또는 전혀없는 스텁 항목을 허용합니다. 이것은 여러 위키 낱말 사전에서 흔했지만 영어 위키 낱말 사전에서는 그렇지 않았습니다. 하지만 이제는 영어 위키 낱말 사전에도 퍼져있는 것 같습니다 : https://en.wiktionary.org/wiki/%E6%99%B6%E7%90%83 (스텁이 채워지면 계속 볼 수 있도록 영구 링크 스텁의 모양 : https://en.wiktionary.org/w/index.php?title=%E6%99%B6%E7%90%83&oldid=39757161 )

이것이 원하는 내용에 포함되어 있지 않으면 위키 텍스트 자체를로드하고 구문 분석해야하며 이는 간단한 작업이 아닙니다.


Wikitionary 데이터 덤프를 다운로드 할 수 있습니다 . FAQ에 더 많은 정보가 있습니다 . 사용자의 목적에 따라 정의 덤프 가 xml 덤프보다 더 나은 선택 일 것입니다.


정말 간단하게 유지하려면 다음과 같이 덤프에서 단어를 추출하십시오.

bzcat pages-articles.xml.bz2 | grep '<title>[^[:space:][:punct:]]*</title>' | sed 's:.*<title>\(.*\)</title>.*:\1:' > words

Python을 사용 하는 경우 Suyash Behera의 WiktionaryParser사용할 수 있습니다 .

다음 방법으로 설치할 수 있습니다.

sudo pip install wiktionaryparser

사용 예 :

>>> from wiktionaryparser import WiktionaryParser
>>> parser = WiktionaryParser()
>>> word = parser.fetch('test')
>>> another_word = parser.fetch('test', 'french')
>>> parser.set_default_language('french')

JWKTL을 사용해 볼 수도 있습니다. 나는 그것에 대해 방금 알게되었습니다.)

http://en.wikipedia.org/wiki/Ubiquitous_Knowledge_Processing_Lab#Wiktionary_API

http://www.ukp.tu-darmstadt.de/software/jwktl/


어원 및 발음 데이터 구문 분석을 시작합니다.

function parsePronunciationLine(line) {
  let val
  let type
  line.replace(/\{\{\s*a\s*\|UK\s*\}\}\s*\{\{IPA\|\/?([^\/\|]+)\/?\|lang=en\}\}/, (_, $1) => {
    val = $1
    type = 'uk'
  })
  line.replace(/\{\{\s*a\s*\|US\s*\}\}\s*\{\{IPA\|\/?([^\/\|]+)\/?\|lang=en\}\}/, (_, $1) => {
    val = $1
    type = 'us'
  })
  line.replace(/\{\{enPR|[^\}]+\}\},?\s*\{\{IPA\|\/?([^\/\|]+)\/?\|lang=en}}/, (_, $1) => {
    val = $1
    type = 'us'
  })
  line.replace(/\{\{a|GA\}\},?\s*\{\{IPA\|\/?([^\/\|]+)\/?\|lang=en}}/, (_, $1) => {
    val = $1
    type = 'ga'
  })
  line.replace(/\{\{a|GA\}\},?.+\{\{IPA\|\/?([^\/\|]+)\/?\|lang=en}}/, (_, $1) => {
    val = $1
    type = 'ga'
  })
  // {{a|GA}} {{IPA|/ˈhæpi/|lang=en}}
  // * {{a|RP}} {{IPA|/pliːz/|lang=en}}
  // * {{a|GA}} {{enPR|plēz}}, {{IPA|/pliz/|[pʰliz]|lang=en}}

  if (!val) return

  return { val, type }
}

function parseEtymologyPiece(piece) {
  let parts = piece.split('|')
  parts.shift() // first one is ignored.
  let ls = []
  if (langs[parts[0]]) {
    ls.push(parts.shift())
  }
  if (langs[parts[0]]) {
    ls.push(parts.shift())
  }
  let l = ls.pop()
  let t = parts.shift()
  return [ l, t ]
  // {{inh|en|enm|poisoun}}
  // {{m|enm|poyson}}
  // {{der|en|la|pōtio|pōtio, pōtiōnis|t=drink, a draught, a poisonous draught, a potion}}
  // {{m|la|pōtō|t=I drink}}
  // {{der|en|enm|happy||fortunate, happy}}
  // {{cog|is|heppinn||lucky}}
}

업데이트 : 여기 에 더 구체화 된 요점이 있습니다.


As mentioned earlier, the problem with this approach is that Wiktionary provides the information about all the words of all the languages. So the approach to check if a page exists using Wikipedia API won't work because there're a lot of pages for non-English words. To overcome this, you need to parse each page to figure out if there's a section describing English word. Parsing wikitext isn't a trivial task, though in your case it's not that bad. To cover almost all the cases you need to just check if the wikitext contains English heading. Depending on the programming language you use, you can find some tools to build AST from wikitext. This will cover most of the cases, but not all of them because Wiktionary includes some common misspellings.

As an alternative, you could try using Lingua Robot or something similar. Lingua Robot parses the Wiktionary content and provide it as a REST API. Non-empty response means that the word exists. Please note that, as opposed to Wiktionary, the API itself doesn't include any misspellings (at least at the moment of writing this answer). Please also note that the Wiktionary contains not only the words, but multi-word expressions.

참고URL : https://stackoverflow.com/questions/2770547/how-to-retrieve-wiktionary-word-content

반응형