<jupyter_start><jupyter_text>This notebook is dealing with very simple relation extraction. On the input, there is file with pair (word|definition) on each line. Output is pair (work = hypernym).Current solution is looking at part of speech tags and takes the first noun as hypernym.<jupyter_code>!wget https://nlp.fi.muni.cz/trac/research/chrome/site/bigdata/ia161-hyper.zip
!unzip ia161-hyper.zip
%cd ia161-hyper
!pip install majka
import re
import sys
import string
import majka

majka = majka.Majka("majka/majka.w-lt")

def has_pos(word, pos):
	tags = majka.find(word)
	#print(tags)
	match = [x for x in tags if x and x['tags'] and x['tags']['pos'] == pos]
	if len(match) > 0 and len(match) == len(tags):
		return match[0]['lemma']
	else:
		return False

def find_hyper(word, text):
	text = re.sub('[(),]', '', text)
	for w in text.split():
		lemma = has_pos(w, 'substantive')
		if lemma:
			return (word,lemma)
	return (word,u'')


def extract():
	vstup = 'vstup.txt'
	for line in open(vstup, 'r'):
		if line.strip() != '':
			line_split = line.strip().split('|')
			hyper = find_hyper(line_split[0], line_split[1])
			print("%s = %s" % hyper)
!cat vstup.txt
extract()<jupyter_output>židle = nábytek
stůl = nábytek
růže = keř
bylina = rostlina
geografická informační věda = obor
globografie = část
kartograf = pracovník
pes = šelma
tygr = šelma
hroch = savec
slunečnice = bylina
kůň = jednokopytník
člověk = bytost
tesař = řemeslník
nosič = nošení
loď = plavidlo
parník = stroj
buk = strom
lípa = strom
violka = bylina
žirafa = kopytnatec
klokan = savec
hlava = část
krk = část
včela = hmyz
chléb = pečivo
dort = druh
kráva = samice
los = savec
nos = část
kočka = šelma
{'fraction_non_alphanumeric': 0.12783751493428913, 'fraction_numerical': 0.007765830346475508, 'mean_word_length': 4.403225806451613, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '128748', 'license': 'MIT', 'n_tokens_mistral': 711, 'n_tokens_neox': 694, 'n_words': 193, 'path': 'Relation_Extraction/IA161_Relation_Extraction.ipynb', 'repo_name': 'katarinagresova/ia161', 'size': '1674'}