yanbe.diff このページをアンテナに追加 RSSフィード



 日本語WordNetのデータベースを探索するフロントエンドプログラム - yanbe.diff を含むブックマーク はてなブックマーク -  日本語WordNetのデータベースを探索するフロントエンドプログラム - yanbe.diff  日本語WordNetのデータベースを探索するフロントエンドプログラム - yanbe.diff のブックマークコメント


日本語WordNetのバージョンは0.9、Pythonのバージョンは2.6.1、OSMac OS X 10.5.6で動作確認しました。




追記:以下のコードを http://gist.github.com/79057 に貼りました。

#!/usr/bin/env python2.6
# encoding: utf-8
import sys
import sqlite3
from collections import namedtuple

conn = sqlite3.connect("wnjpn-0.9.db")

Word = namedtuple('Word', 'wordid lang lemma pron pos')

def getWords(lemma):
  words = []
  cur = conn.execute("select * from word where lemma=?", (lemma,))
  row = cur.fetchone()
  while row:
    row = cur.fetchone()
  return words

def getWord(wordid):
  cur = conn.execute("select * from word where wordid=?", (wordid,))
  return Word(*cur.fetchone())
Sense = namedtuple('Sense', 'synset wordid lang rank lexid freq src')

def getSenses(word):
  senses = []
  cur = conn.execute("select * from sense where wordid=?", (word.wordid,))
  row = cur.fetchone()
  while row:
    row = cur.fetchone()
  return senses

def getSense(synset, lang='jpn'):
  cur = conn.execute("select * from sense where synset=? and lang=?",
  row = cur.fetchone()
  if row:
    return Sense(*row)
    return None

Synset = namedtuple('Synset', 'synset pos name src')

def getSynset(synset):
  cur = conn.execute("select * from synset where synset=?", (synset,))
  row = cur.fetchone()
  if row:
    return Synset(*row)
    return None

SynLink = namedtuple('SynLink', 'synset1 synset2 link src')

def getSynLinks(sense, link):
  synLinks = []
  cur = conn.execute("select * from synlink where synset1=? and link=?", (sense.synset, link))
  row = cur.fetchone()
  while row:
    row = cur.fetchone()
  return synLinks

def getSynLinksRecursive(senses, link, lang='jpn', _depth=0):
  for sense in senses:
    synLinks = getSynLinks(sense, link)
    if synLinks:
      print '  '*_depth + getWord(sense.wordid).lemma, getSynset(sense.synset).name
    _senses = []
    for synLink in synLinks:
      sense = getSense(synLink.synset2, lang)
      if sense:
    getSynLinksRecursive(_senses, link, lang, _depth+1)

if __name__ == '__main__':
  if len(sys.argv)>=3:
    words = getWords(sys.argv[1].decode('utf-8'))
    if words:
      sense = getSenses(words[0])
      link = sys.argv[2]
      lang = len(sys.argv)==4 and sys.argv[3] or 'jpn'
      getSynLinksRecursive(sense, link, lang)
      print >>sys.stderr, "(nothing found)"
    print """usage: wn.py word link [lang]
      word to investigate

      syns - Synonyms
      hype - Hypernyms
      inst - Instances
      hypo - Hyponym
      hasi - Has Instance
      mero - Meronyms
      mmem - Meronyms --- Member
      msub - Meronyms --- Substance
      mprt - Meronyms --- Part
      holo - Holonyms
      hmem - Holonyms --- Member
      hsub - Holonyms --- Substance
      hprt - Holonyms -- Part
      attr - Attributes
      sim - Similar to
      entag - Entails
      causg - Causes
      dmncg - Domain --- Category
      dmnug - Domain --- Usage
      dmnrg - Domain --- Region
      dmtcg - In Domain --- Category
      dmtug - In Domain --- Usage
      dmtrg - In Domain --- Region
      antsg - Antonyms

    lang (default: jpn) 
      jpn - Japanese
      eng - English

pedro marcalpedro marcal2010/03/29 01:19is it possible to obtain the program that was used to build the sqlite database for python?

y_yanbey_yanbe2010/06/05 17:15I couldn't understand what you mean well.

You can build sqlite database by using "sqlite3" module which was introduced as standard module since Python 2.5.

If you want to download Japanese version of Wordnet corpus database, You can download it from following link. http://nlpwww.nict.go.jp/wn-ja/index.en.html

In what you want to know the tool to be used for building Japanese version of WordNet corpus, I have no idea about it.

r_gr_g2011/08/24 12:02Python 2.7.2 / Mac OS 10.6.8の環境で確認しておりますが、hypo/hype以外のlinkの結果は空になっています。お手数ですが、なにかアイデアはありますでしょうか?

KristabelleKristabelle2011/11/01 10:43You really found a way to make this whole procses easier.

cgomymacgomyma2011/11/01 23:59iDY1p5 <a href="http://svaykfpkxhzw.com/">svaykfpkxhzw</a>

augijhnaugijhn2011/11/03 21:10PomOCE , [url=http://znmopnycisdg.com/]znmopnycisdg[/url], [link=http://pjbgyyzxhkmn.com/]pjbgyyzxhkmn[/link], http://yocfzcuaeual.com/

xszghkssmexszghkssme2011/11/05 03:5699VHxS <a href="http://mzhgcmbbklly.com/">mzhgcmbbklly</a>

katryokatryo2014/01/18 22:36Python3.3で動くように書き換えました。Githubに置いたので、自由に使ってください。 https://github.com/katryo/wordnet_python