Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
e6f09a10
Commit
e6f09a10
authored
Feb 26, 2016
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DOC] documented the `Node` model
parent
883a52c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
3 deletions
+33
-3
nodes.py
gargantext/models/nodes.py
+33
-3
No files found.
gargantext/models/nodes.py
View file @
e6f09a10
...
...
@@ -12,7 +12,7 @@ __all__ = ['Node']
class
NodeType
(
TypeDecorator
):
"""Define a new type of column to describe a Node's type.
T
his column type is implemented as an SQL integer.
Internally, t
his column type is implemented as an SQL integer.
Values are detailed in `gargantext.constants.NODETYPES`.
"""
impl
=
Integer
...
...
@@ -22,6 +22,11 @@ class NodeType(TypeDecorator):
return
NODETYPES
[
typeindex
]
class
Node
(
Base
):
"""This model can fit many purposes.
It intends to provide a generic model, allowing hierarchical structure
and NoSQL-like data structuring.
The possible types are defined in `gargantext.constants.NODETYPES`.
"""
__tablename__
=
'nodes'
id
=
Column
(
Integer
,
primary_key
=
True
)
typename
=
Column
(
NodeType
,
index
=
True
)
...
...
@@ -35,18 +40,29 @@ class Node(Base):
hyperdata
=
Column
(
JSONB
,
default
=
dict
)
def
__init__
(
self
,
**
kwargs
):
"""Node's constructor.
Initialize the `hyperdata` as a dictionary if no value was given.
"""
if
'hyperdata'
not
in
kwargs
:
kwargs
[
'hyperdata'
]
=
kwargs
.
get
(
'hyperdata'
,
{}
)
kwargs
[
'hyperdata'
]
=
kwargs
.
get
(
'hyperdata'
,
MutableDict
()
)
Base
.
__init__
(
self
,
**
kwargs
)
def
__getitem__
(
self
,
key
):
"""Allow direct access to hyperdata via the bracket operator.
"""
return
self
.
hyperdata
[
key
]
def
__setitem__
(
self
,
key
,
value
):
"""Allow direct access to hyperdata via the bracket operator.
"""
self
.
hyperdata
[
key
]
=
value
@
property
def
ngrams
(
self
):
"""Pseudo-attribute allowing to retrieve a node's ngrams.
Returns a query (which can be further filtered), of which returned rows
are the ngram's weight for this node and the ngram.
"""
from
.
import
NodeNgram
,
Ngram
query
=
(
session
.
query
(
NodeNgram
.
weight
,
Ngram
)
...
...
@@ -57,6 +73,10 @@ class Node(Base):
return
query
def
as_list
(
self
):
"""Retrieve the current node as a list/matrix of ngrams identifiers.
See `gargantext.util.lists` and `gargantext.constants.LISTTYPES`
for more info.
"""
try
:
return
LISTTYPES
[
self
.
typename
](
self
.
id
)
except
KeyError
:
...
...
@@ -100,17 +120,27 @@ class Node(Base):
)
def
resources
(
self
):
"""Return all the resources attached to a given node.
Mainly used for corpora.
"""
if
'resources'
not
in
self
.
hyperdata
:
self
[
'resources'
]
=
MutableList
()
return
self
[
'resources'
]
def
add_resource
(
self
,
type
,
path
=
None
,
url
=
None
):
"""Attach a resource to a given node.
Mainly used for corpora.
"""
self
.
resources
()
.
append
(
MutableDict
(
{
'type'
:
type
,
'path'
:
path
,
'url'
:
url
,
'extracted'
:
False
}
))
def
status
(
self
,
action
=
None
,
progress
=
0
,
complete
=
False
,
error
=
None
):
"""Get the status of the given action
"""Get or update the status of the given action.
If no action is given, the status of the first uncomplete or last item
is returned.
The `complete` parameter should be a boolean.
The `error` parameter should be an exception.
"""
date
=
datetime
.
now
()
# if the hyperdata do not have data about status
...
...
Write
Preview
Markdown
is supported
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