LoginSignup
2
1

More than 5 years have passed since last update.

日本語wordnet の連想辞書のjson化

Last updated at Posted at 2019-04-06

demo https://codepen.io/gnjo/pen/MReGoB

1: .jsonならば一度読めばキャッシュから読み込める事を利用して連想辞書の高速検索を行う。
2: json化する。大本のデータは以下、タブ区切りで十五万要素ある。4MB程度。
original http://compling.hss.ntu.edu.sg/wnja/jpn/downloads.html

データ形式

連想番号-品詞\t単語\t人か物かのグループ

例では読み込み専用ファイルと読み出し専用ファイルの連想番号は同じである為、結果、類義語。

06510836-n  読み込み専用ファイル  hand
06510836-n  読み出し専用ファイル  hand

3: タブ形式は扱いにくい。jsonに変換する。連想番号末尾の品詞も分ける事で高速化する。6MB程度。
https://raw.githubusercontent.com/gnjo/gnjo.github.io/master/wnjpn-ok.tab.json

データ形式

[[連想番号,-品詞,単語,人かモノ]]
[
[06510836,-n,読み込み専用ファイル,hand]
,[06510836,-n,読み出し専用ファイル,hand]
... arrray over the 150,000
]
//get json
 (async ()=>{
  const url='https://raw.githubusercontent.com/gnjo/gnjo.github.io/master/wnjpn-ok.tab.json'
  ,ary=await fetch(url).then(d=>d.json() )
  ...
 })();

4: 検索は.filter等で検索単語で取得できた配列の連想番号を取得して、今度は連想番号でフィルターをかければよい。

//core
function calc(ary,word='',max=5){
 if(word.length===0) return [] 
 return ary.filter(d=> ~d[2].indexOf(word) ).slice(0,max) //search the containts words
  .map(d=>d[0]).map(num=> ary.filter(d=>d[0]===num) ) //search syno...m
  .reduce((a,b)=> a.concat(b) ) //flattan
 ;
}

ライセンス

日本語ワードネット (1.1版)© 2009-2011 NICT, 2012-2015 Francis Bond and 2016-2017 Francis Bond, Takayuki Kuribayashi 
linked to http://compling.hss.ntu.edu.sg/wnja/index.ja.html

追記 ウェブワーカー版。選択した用語の連想語をリアルタイムで検索。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1