Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neeme Kahusk
eurown
Commits
0c05548f
Commit
0c05548f
authored
Nov 16, 2016
by
Neeme Kahusk
Browse files
Synset.variants=None
parent
8d1c0388
Changes
2
Hide whitespace changes
Inline
Side-by-side
eurown.py
View file @
0c05548f
...
...
@@ -10,7 +10,7 @@ This is the new eurown module.
>>> c = eurown.Variant('elajas',2)
>>> a.add_variant(b)
>>> print(a)
0 @43
-n
@ WORD_MEANING
0 @43@ WORD_MEANING
1 PART_OF_SPEECH "n"
1 VARIANTS
2 LITERAL "loom"
...
...
@@ -23,7 +23,7 @@ This is the new eurown module.
3 SENSE 2
>>> a.add_variant(c)
>>> print(a)
0 @43
-n
@ WORD_MEANING
0 @43@ WORD_MEANING
1 PART_OF_SPEECH "n"
1 VARIANTS
2 LITERAL "loom"
...
...
@@ -33,7 +33,7 @@ This is the new eurown module.
>>> a.variants[0].gloss = "elusorganism, mida tavaliselt iseloomustab
\
vabatahtliku liikumise võime ja närvisüsteemi olemasolu"
>>> print(a)
0 @43
-n
@ WORD_MEANING
0 @43@ WORD_MEANING
1 PART_OF_SPEECH "n"
1 VARIANTS
2 LITERAL "loom"
...
...
@@ -70,9 +70,8 @@ def format_polaris(level, field, value=None,
return
out
class
Synset
:
ids
=
[]
def
__init__
(
self
,
id
=
''
,
pos
=
'n'
,
variants
=
[],
class
Synset
(
object
):
def
__init__
(
self
,
number
=
''
,
pos
=
'n'
,
variants
=
None
,
internal_links
=
[],
eq_links
=
[],
property_values
=
[]):
self
.
pos
=
pos
...
...
@@ -80,25 +79,36 @@ class Synset:
self
.
internal_links
=
internal_links
self
.
eq_links
=
eq_links
self
.
property_values
=
property_values
if
id
:
self
.
id
=
'{}-{}'
.
format
(
id
,
self
.
pos
)
else
:
self
.
id
=
''
self
.
number
=
number
# if id:
# self.id = '{}-{}'.format(id, self.pos)
# else:
# self.id = ''
self
.
fieldname
=
'WORD_MEANING'
def
add_variant
(
self
,
variant
):
if
not
self
.
variants
:
self
.
variants
=
[]
self
.
variants
.
append
(
variant
)
def
add_internal_link
(
self
,
internal_link
):
self
.
internal_links
.
append
(
internal_link
)
def
add_eq_link
(
self
,
eq_link
):
self
.
eq_links
.
append
(
eq_link
)
def
__str__
(
self
):
if
self
.
id
:
out
=
format_polaris
(
0
,
'WORD_MEANING'
,
None
,
self
.
id
)
if
self
.
number
:
out
=
format_polaris
(
0
,
self
.
fieldname
,
None
,
self
.
number
)
else
:
out
=
format_polaris
(
0
,
'WORD_MEANING'
)
out
=
format_polaris
(
0
,
self
.
fieldname
)
if
self
.
pos
:
# should always be true
out
=
'{}
\n
{}'
.
format
(
out
,
format_polaris
(
1
,
'PART_OF_SPEECH'
,
self
.
pos
)
)
)
if
self
.
variants
:
out
=
'{}
\n
{}'
.
format
(
out
,
format_polaris
(
1
,
...
...
@@ -107,6 +117,22 @@ class Synset:
out
=
'{}
\n
{}'
.
format
(
out
,
'
\n
'
.
join
([
str
(
i
)
for
i
in
self
.
variants
])
)
if
self
.
internal_links
:
out
=
'{}
\n
{}'
.
format
(
out
,
format_polaris
(
1
,
'INTERNAL_LINKS'
)
)
out
=
'{}
\n
{}'
.
format
(
out
,
'
\n
'
.
join
([
str
(
i
)
for
i
in
self
.
internal_links
])
)
if
self
.
eq_links
:
out
=
'{}
\n
{}'
.
format
(
out
,
format_polaris
(
1
,
'EQ_LINKS'
)
)
out
=
'{}
\n
{}'
.
format
(
out
,
'
\n
'
.
join
([
str
(
i
)
for
i
in
self
.
eq_links
])
)
return
out
...
...
@@ -152,11 +178,14 @@ class Variant:
return
out
class
InternalLink
:
def
__init__
(
self
,
name
=
None
):
def
__init__
(
self
,
name
,
target_concept
,
features
=
[]):
self
.
name
=
name
self
.
target_concept
=
target_concept
self
.
features
=
features
if
__name__
==
'__main__'
:
print
(
format_polaris
(
0
,
'WORD_MEANING'
,
record
=
222
))
#
print(format_polaris(0, 'WORD_MEANING', record=222))
import
doctest
doctest
.
testmod
()
eurown_test.ipynb
0 → 100644
View file @
0c05548f
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Eurown testing"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
">>> import eurown\n",
">>> a = eurown.Synset(43)\n",
">>> b = eurown.Variant('loom',1)\n",
">>> c = eurown.Variant('elajas',2)\n",
">>> a.add_variant(b)\n",
">>> print(a)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
">>> print(b)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
">>> print(c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
">>> a.add_variant(c)\n",
">>> print(a)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
">>> a.variants[0].gloss = \"elusorganism, mida tavaliselt iseloomustab \\\n",
"vabatahtliku liikumise võime ja närvisüsteemi olemasolu\"\n",
">>> print(a)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"d = eurown.Synset(44)\n",
"print(d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"d.add_variant(eurown.Variant('elusolend',1))\n",
"d.add_variant(eurown.Variant('organism',2))\n",
"d.variants[0].gloss = 'elusorganism, hrl. inimene v. loom'\n",
"print(d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"snset = eurown.Synset()\n",
"print(snset)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "IPython (Python 3)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
%% Cell type:markdown id: tags:
# Eurown testing
%% Cell type:code id: tags:
```
python
>>>
import
eurown
>>>
a
=
eurown
.
Synset
(
43
)
>>>
b
=
eurown
.
Variant
(
'loom'
,
1
)
>>>
c
=
eurown
.
Variant
(
'elajas'
,
2
)
>>>
a
.
add_variant
(
b
)
>>>
print
(
a
)
```
%% Cell type:code id: tags:
```
python
>>>
print
(
b
)
```
%% Cell type:code id: tags:
```
python
>>>
print
(
c
)
```
%% Cell type:code id: tags:
```
python
>>>
a
.
add_variant
(
c
)
>>>
print
(
a
)
```
%% Cell type:code id: tags:
```
python
>>>
a
.
variants
[
0
].
gloss
=
"elusorganism, mida tavaliselt iseloomustab
\
vabatahtliku liikumise võime ja närvisüsteemi olemasolu"
>>>
print
(
a
)
```
%% Cell type:code id: tags:
```
python
d
=
eurown
.
Synset
(
44
)
print
(
d
)
```
%% Cell type:code id: tags:
```
python
d
.
add_variant
(
eurown
.
Variant
(
'elusolend'
,
1
))
d
.
add_variant
(
eurown
.
Variant
(
'organism'
,
2
))
d
.
variants
[
0
].
gloss
=
'elusorganism, hrl. inimene v. loom'
print
(
d
)
```
%% Cell type:code id: tags:
```
python
snset
=
eurown
.
Synset
()
print
(
snset
)
```
%% Cell type:code id: tags:
```
python
```
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment