mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-14 13:47:13 +03:00
* Fix init_model to read supersenses from wordnet, not pre-computed supersenses file
This commit is contained in:
parent
b977d60bf4
commit
ff1f9fe246
|
@ -28,7 +28,7 @@ from spacy.en.lemmatizer import Lemmatizer
|
||||||
from spacy.vocab import Vocab
|
from spacy.vocab import Vocab
|
||||||
from spacy.vocab import write_binary_vectors
|
from spacy.vocab import write_binary_vectors
|
||||||
|
|
||||||
from spacy.parts_of_speech import NOUN, VERB, ADJ
|
from spacy.parts_of_speech import NOUN, VERB, ADJ, ADV
|
||||||
|
|
||||||
import spacy.senses
|
import spacy.senses
|
||||||
|
|
||||||
|
@ -80,19 +80,14 @@ def _read_probs(loc):
|
||||||
|
|
||||||
def _read_senses(loc):
|
def _read_senses(loc):
|
||||||
lexicon = defaultdict(lambda: defaultdict(list))
|
lexicon = defaultdict(lambda: defaultdict(list))
|
||||||
sense_names = dict((s, i) for i, s in enumerate(spacy.senses.STRINGS))
|
pos_tags = [None, NOUN, VERB, ADJ, ADV, None]
|
||||||
pos_ids = {'noun': NOUN, 'verb': VERB, 'adjective': ADJ}
|
|
||||||
for line in codecs.open(str(loc), 'r', 'utf8'):
|
for line in codecs.open(str(loc), 'r', 'utf8'):
|
||||||
sense_strings = line.split()
|
sense_key, synset_offset, sense_number, tag_cnt = line.split()
|
||||||
word = sense_strings.pop(0)
|
lemma, lex_sense = sense_key.split('%')
|
||||||
for sense in sense_strings:
|
ss_type, lex_filenum, lex_id, head_word, head_id = lex_sense.split(':')
|
||||||
pos, sense = sense[3:].split('.')
|
pos = pos_tags[int(ss_type)]
|
||||||
if pos[0].upper() == 'A':
|
if pos is not None:
|
||||||
continue
|
lexicon[lemma][pos].append(int(lex_filenum))
|
||||||
sense_name = '%s_%s' % (pos[0].upper(), sense.lower())
|
|
||||||
if sense_name != 'N_tops':
|
|
||||||
sense_id = sense_names[sense_name]
|
|
||||||
lexicon[word][pos_ids[pos]].append(sense_id)
|
|
||||||
return lexicon
|
return lexicon
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,7 +100,7 @@ def setup_vocab(src_dir, dst_dir):
|
||||||
write_binary_vectors(str(vectors_src), str(dst_dir / 'vec.bin'))
|
write_binary_vectors(str(vectors_src), str(dst_dir / 'vec.bin'))
|
||||||
vocab = Vocab(data_dir=None, get_lex_props=get_lex_props)
|
vocab = Vocab(data_dir=None, get_lex_props=get_lex_props)
|
||||||
clusters = _read_clusters(src_dir / 'clusters.txt')
|
clusters = _read_clusters(src_dir / 'clusters.txt')
|
||||||
senses = _read_senses(src_dir / 'supersenses.txt')
|
senses = _read_senses(src_dir / 'wordnet' / 'index.sense')
|
||||||
probs = _read_probs(src_dir / 'words.sgt.prob')
|
probs = _read_probs(src_dir / 'words.sgt.prob')
|
||||||
for word in set(clusters).union(set(senses)):
|
for word in set(clusters).union(set(senses)):
|
||||||
if word not in probs:
|
if word not in probs:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user