0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonでつくる対話システム(その先)

Last updated at Posted at 2022-05-14

類義語フリーの辞書

参考ページ

pysqlite3 インストール

pip install pysqlite3 

どんなテーブルがあるか

import sqlite3
conn = sqlite3.connect("wnjpn.db")

cur = conn.execute("select name from sqlite_master where type='table'")
for row in cur:
    print(row)

結果

('link_def',)
('synset_def',)
('synset_ex',)
('synset',)
('synlink',)
('ancestor',)
('sense',)
('word',)
('variant',)
('xlink',)

image.png

関連テーブルの構造調査

調査コード

cur = conn.execute("select * from <table_name> limit 10")
for row in cur:
    print(row)

# Wordnetデータに含まれるカラムの確認
cur = conn.execute("PRAGMA TABLE_INFO(<table_name>)")
for row in cur:
    print(row)

wordテーブルの構造

列名

(0, 'wordid', 'integer', 0, None, 1)
(1, 'lang', 'text', 0, None, 0)
(2, 'lemma', 'text', 0, None, 0)
(3, 'pron', 'text', 0, None, 0)
(4, 'pos', 'text', 0, None, 0)

データ

(1, 'eng', 'expletive', None, 'n')
(2, 'eng', 'measles', None, 'n')
(3, 'eng', 'contras', None, 'n')
(4, 'eng', 'beef_man', None, 'n')
(5, 'eng', 'dwelling', None, 'n')
(6, 'eng', 'acetum', None, 'n')
(7, 'eng', 'mount_carmel', None, 'n')
(8, 'eng', 'class_taxopsida', None, 'n')
(9, 'eng', 'vascular_ray', None, 'n')
(10, 'eng', 'genus_salamandra', None, 'n')

senseテーブルの構造

列名

(0, 'synset', 'text', 0, None, 0)
(1, 'wordid', 'integer', 0, None, 0)
(2, 'lang', 'text', 0, None, 0)
(3, 'rank', 'text', 0, None, 0)
(4, 'lexid', 'integer', 0, None, 0)
(5, 'freq', 'integer', 0, None, 0)
(6, 'src', 'text', 0, None, 0)

データ

('07125096-n', 1, 'eng', '0', 1, 1, 'eng-30')
('07126228-n', 1, 'eng', '0', 2, 0, 'eng-30')
('14123044-n', 2, 'eng', '0', 1, 0, 'eng-30')
('08030185-n', 3, 'eng', '0', 1, 0, 'eng-30')
('09902017-n', 4, 'eng', '0', 1, 1, 'eng-30')
('03259505-n', 5, 'eng', '0', 1, 11, 'eng-30')
('14599641-n', 6, 'eng', '0', 1, 0, 'eng-30')
('07828987-n', 6, 'eng', '0', 2, 0, 'eng-30')
('09361816-n', 7, 'eng', '0', 1, 0, 'eng-30')
('11660537-n', 8, 'eng', '0', 1, 0, 'eng-30')

synsetテーブルの構造

列名

(0, 'synset', 'text', 0, None, 0)
(1, 'pos', 'text', 0, None, 0)
(2, 'name', 'text', 0, None, 0)
(3, 'src', 'text', 0, None, 0)

データ

('07125096-n', 'n', 'expletive', 'eng30')
('07126228-n', 'n', 'expletive', 'eng30')
('14123044-n', 'n', 'measles', 'eng30')
('08030185-n', 'n', 'contras', 'eng30')
('09902017-n', 'n', 'beef_man', 'eng30')
('03259505-n', 'n', 'dwelling', 'eng30')
('14599641-n', 'n', 'acetum', 'eng30')
('07828987-n', 'n', 'acetum', 'eng30')
('09361816-n', 'n', 'mount_carmel', 'eng30')
('11660537-n', 'n', 'class_taxopsida', 'eng30')

類義語取得手順

  1. wordテーブルからword_id取得
    ex)『パソコン』のword_id:190168
  2. senseテーブルからword_idと一致するもsynsetを取得
    ex)['03918480-n']
  3. synsetテーブルから上記synsetと一致するをnameを取得
    ※複数なので配列に保存
    ex)pc

XML解析

  • lemmaタグの writtenFormがワード
  • LexicalEntryタグの id が word_id('w190168')
  • sensetは同じタグ内にあり
    image.png

##ワードの数
image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?