Cross Reference: symbols.rb
xref
: /
ontohub
/
app
/
models
/
ontology
/
symbols.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
symbols.rb revision 2218ff30ec39253b75bd6cede5fb7683b5f4c503
642
N/A
class
Ontology
642
N/A
module
Symbols
642
N/A
extend
ActiveSupport
::
Concern
642
N/A
642
N/A
included
do
642
N/A
has_many
:
symbols
,
642
N/A
autosave
:
false
,
642
N/A
class_name
:
'OntologyMember::Symbol'
,
642
N/A
extend
:
Methods
642
N/A
end
642
N/A
642
N/A
module
Methods
642
N/A
def
update_or_create_from_hash
(
hash
,
timestamp
=
Time.now
)
642
N/A
raise
ArgumentError
,
'No hash given.'
unless
hash.is
_a
?
Hash
642
N/A
642
N/A
e =
where
(
text
:
hash
[
'text'
])
.
first_or_initialize
642
N/A
642
N/A
e.ontology
= @
association.owner
642
N/A
e.range
=
hash
[
'range'
]
642
N/A
e.updated
_at
=
timestamp
642
N/A
642
N/A
unless
hash
[
'name'
] ||
hash
[
'kind'
]
3143
N/A
Rails.logger.warn
(
3158
N/A
"Using work-around to determine symbol name and kind: #{
e.inspect
}"
)
3143
N/A
642
N/A
if
e2
=
Symbol.where
(
text
:
hash
[
'text'
])
.
first
3143
N/A
e.name
=
e2.name
642
N/A
e.kind
=
e2.kind
642
N/A
else
642
N/A
e.name
=
e.text
642
N/A
e.kind
=
'Undefined'
642
N/A
end
642
N/A
else
642
N/A
e.name
=
hash
[
'name'
]
642
N/A
e.kind
=
hash
[
'kind'
]
642
N/A
end
642
N/A
3234
N/A
e.iri
=
hash
[
'iri'
]
642
N/A
e.label
=
hash
[
'label'
]
642
N/A
642
N/A
sep
=
'//'
642
N/A
locid_portion
=
642
N/A
if
e.name.include
?
(
'://'
)
642
N/A
if
e.label
642
N/A
e.label
642
N/A
else
642
N/A
portion
=
e.name.end
_with
?
(
'>'
)
?
e.name
[
0
..-
2
] :
e.name
642
N/A
portion
=
portion.split
(
'#'
,
2
)
.
last
642
N/A
end
642
N/A
else
642
N/A
e.name
642
N/A
end
642
N/A
e.locid
=
"#{
e.ontology.locid
}#{sep}#{locid_portion}"
642
N/A
642
N/A
if
e.range.to_s.include
?
(
':'
)
3143
N/A
# remove path from range
642
N/A
#
Examples
/
Reichel
:28.9 -> 28.9
3143
N/A
e.range
=
e.range.split
(
':'
,
2
)
.
last
3143
N/A
end
642
N/A
642
N/A
e.ontology.symbols
<< e
if
e.id.nil
?
3143
N/A
e.save
!
3194
N/A
e
3143
N/A
end
3143
N/A
end
642
N/A
642
N/A
def
delete_edges
3143
N/A
%i[
parent_id
child_id
].
each
do
|
key
|
3194
N/A
EEdge.where
(
key
=>
symbols.where
(
kind
:
'Class'
)
)
.
delete_all
3143
N/A
end
3143
N/A
end
642
N/A
642
N/A
def
create_symbol_tree
642
N/A
raise
StandardError.new
(
'Ontology is not OWL'
)
unless
owl
?
642
N/A
642
N/A
# Delete previous set of categories
642
N/A
delete_edges
642
N/A
subclasses
=
642
N/A
sentences.where
(
"text LIKE '%SubClassOf%'"
)
.
select
do
|
sentence
|
642
N/A
sentence.text.split
(
' '
)
.
size
==
4
642
N/A
end
642
N/A
transaction
requires_new
:
true
do
642
N/A
subclasses.each
do
|s|
642
N/A
c1
,
c2
=
s.hierarchical
_class_names
642
N/A
642
N/A
unless
c1
==
'Thing'
||
c2
==
'Thing'
642
N/A
child_id
=
symbols.where
(
'name = ? OR iri = ?'
,
c1
,
c1
)
.first.id
3234
N/A
parent_id
=
symbols.where
(
'name = ? OR iri = ?'
,
c2
,
c2
)
.first.id
642
N/A
3234
N/A
EEdge.create
!
child_id
:
child_id
,
parent_id
:
parent_id
642
N/A
if
EEdge.where
(
child_id
:
child_id
,
parent_id
:
parent_id
)
.first.nil
?
642
N/A
raise
StandardError.new
(
'Circle detected'
)
3234
N/A
end
642
N/A
end
3234
N/A
end
642
N/A
end
642
N/A
end
642
N/A
end
642
N/A
end
642
N/A