-
Notifications
You must be signed in to change notification settings - Fork 1
/
wordNetValueExtraction.py
87 lines (74 loc) · 3.37 KB
/
wordNetValueExtraction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import types
from typing import List
from nltk.corpus import wordnet
from owlready2 import Property, Ontology, get_ontology, ObjectPropertyClass, ThingClass,ClassAtom
import nltk
from rdflib import URIRef
#nltk.download('wordnet')
onto: Ontology = get_ontology("file://vaeontology.rdf").load()
# Search for synonyms and antonyms using WordNet
classes: List[ThingClass] = [c for c in onto.classes()]
values_classes = onto.search(iri = '*SchwartzValues#[A-Z]*')
value_concept_class = onto.search(iri = '*ValueConcept')[0]
synonyms = set()
antonyms = set()
for valuec in values_classes:
word = valuec.name.lower()
for syn in wordnet.synsets(word):
# Selecting relevant synsets.
if word == "value":
# This is just the class bhv:Value.
continue
if word == "power":
if '05' not in syn.name():
# one possessing or exercising power or influence or authority (synset 5)
continue
if word == "security":
if '01' not in syn.name() or '03' not in syn.name():
continue
if word == "focus":
if '01' not in syn.name() or '03' not in syn.name() :
continue
if word == "stimulation":
if '01' not in syn.name() or 'foreplay' in syn.name():
continue
if word == "benevolence":
if '01' not in syn.name():
continue
if word == "dominance":
if '02' not in syn.name() or '01' not in syn.name():
continue
if word == "conservation":
if '01' not in syn.name() or '02' not in syn.name():
continue
if word == "concern":
if 'concern.n.01' not in syn.name() or '02' not in syn.name() or '03' not in syn.name() or '04' not in syn.name():
continue
if word == "nature":
if '04' not in syn.name() or '03' not in syn.name():
continue
if word == "caring":
if 'care.v.01' not in syn.name() or 'caring.s.01' not in syn.name() or 'worry.v.02' not in syn.name():
continue
if word == "thought":
if 'thinking.n.01' not in syn.name() or 'think.v.08' not in syn.name() or 'think.v.03' not in syn.name() or 'think.v.13' not in syn.name():
continue
if word == "action":
if 'action.n.06' not in syn.name() or 'action.n.02' not in syn.name():
continue
if word == "face":
if 'face.n.03' not in syn.name() or 'face.n.11' not in syn.name() or 'boldness.n.02' not in syn.name():
continue
for lemma in syn.lemmas():
if lemma.name().lower() != word:
synonyms.add(lemma.name())
if len(onto.search(iri='*' + lemma.name().capitalize() + '*')) == 0:
with onto:
cls = types.new_class(lemma.name().capitalize(), (valuec,))
print(cls)
print(cls.is_a)
cls.label = [lemma.name().capitalize(),]
cls.comment = [f"{lemma.name().capitalize()}: {syn.definition()}", "Term added automatically"]
cls.namespace = onto.get_namespace('https://w3id.org/def/vaeontology#')
print(synonyms)
onto.save("vaeontology_nor.rdf",)