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
c50f2fff
Commit
c50f2fff
authored
Oct 28, 2014
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAUTURE] Resource model implementation.
parent
96420c1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
11 deletions
+43
-11
models.py
node/models.py
+38
-11
test-parsing_from_node.py
test-parsing_from_node.py
+5
-0
No files found.
node/models.py
View file @
c50f2fff
...
@@ -12,7 +12,7 @@ from django.contrib.auth.models import User
...
@@ -12,7 +12,7 @@ from django.contrib.auth.models import User
from
collections
import
defaultdict
from
collections
import
defaultdict
# Some usefull functions
# Some usefull functions
# TODO: start the function name with an underscore (private)
def
upload_to
(
instance
,
filename
):
def
upload_to
(
instance
,
filename
):
return
'corpora/
%
s/
%
s'
%
(
instance
.
user
.
username
,
filename
)
return
'corpora/
%
s/
%
s'
%
(
instance
.
user
.
username
,
filename
)
#return 'corpora/%s/%f/%s' % (instance.user.username, time(), filename)
#return 'corpora/%s/%f/%s' % (instance.user.username, time(), filename)
...
@@ -41,7 +41,8 @@ class Ngram(models.Model):
...
@@ -41,7 +41,8 @@ class Ngram(models.Model):
class
Resource
(
models
.
Model
):
class
Resource
(
models
.
Model
):
guid
=
models
.
CharField
(
max_length
=
255
)
guid
=
models
.
CharField
(
max_length
=
255
)
bdd_type
=
models
.
ForeignKey
(
DatabaseType
,
blank
=
True
,
null
=
True
)
bdd_type
=
models
.
ForeignKey
(
DatabaseType
,
blank
=
True
,
null
=
True
)
#file = models.FileField(upload_to=upload_to, blank=True)
file
=
models
.
FileField
(
upload_to
=
upload_to
,
blank
=
True
)
digest
=
models
.
CharField
(
max_length
=
32
)
# MD5 digest
class
NodeType
(
models
.
Model
):
class
NodeType
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
200
)
name
=
models
.
CharField
(
max_length
=
200
)
...
@@ -59,7 +60,8 @@ class Node(CTENode):
...
@@ -59,7 +60,8 @@ class Node(CTENode):
date
=
models
.
DateField
(
default
=
timezone
.
now
,
blank
=
True
)
date
=
models
.
DateField
(
default
=
timezone
.
now
,
blank
=
True
)
metadata
=
hstore
.
DictionaryField
(
blank
=
True
)
metadata
=
hstore
.
DictionaryField
(
blank
=
True
)
# TODO: remove the three following fields
fichier
=
models
.
FileField
(
upload_to
=
upload_to
,
blank
=
True
)
fichier
=
models
.
FileField
(
upload_to
=
upload_to
,
blank
=
True
)
#resource = models.ForeignKey(Resource, blank=True, null=True)
#resource = models.ForeignKey(Resource, blank=True, null=True)
#ngrams = models.ManyToManyField(NGrams)
#ngrams = models.ManyToManyField(NGrams)
...
@@ -67,15 +69,36 @@ class Node(CTENode):
...
@@ -67,15 +69,36 @@ class Node(CTENode):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
# TODO: voir à quoi sert cette méthode
def
liste
(
self
,
user
):
def
liste
(
self
,
user
):
for
noeud
in
Node
.
objects
.
filter
(
user
=
user
):
for
noeud
in
Node
.
objects
.
filter
(
user
=
user
):
print
(
noeud
.
depth
*
" "
+
"[
%
d]
%
d"
%
(
noeud
.
pk
,
noeud
.
name
))
print
(
noeud
.
depth
*
" "
+
"[
%
d]
%
d"
%
(
noeud
.
pk
,
noeud
.
name
))
def
add_resource
(
self
,
**
kwargs
):
resource
=
Resource
(
**
kwargs
)
# TODO: vérifier si tous ces 'save' sont réellement utiles
resource
.
save
()
node_resource
=
Node_Resource
(
node
=
self
,
resource
=
resource
)
node_resource
.
save
()
return
resource
def
parse
(
self
):
# TODO: that's not very pretty...
# can't we make a simple join in Django?
for
node_resource
in
self
.
node_resource
.
filter
(
parsed
=
False
):
# TODO: call parsers here
print
(
node_resource
.
resource
.
file
)
def
extract_ngrams
(
self
,
keys
,
cache
):
def
extract_ngrams
(
self
,
keys
,
cache
):
# TODO: instanciate the ngrams extractors
# what do we want from the cache?
# WHERE TO PUT THEIR CACHE?
extractor
=
cache
.
extractors
[
self
.
language
]
extractor
=
cache
.
extractors
[
self
.
language
.
iso2
]
ngrams
=
cache
.
ngrams
[
self
.
language
]
ngrams
=
cache
.
ngrams
[
self
.
language
]
# find & count all the occurrences
# find & count all the occurrences
associations
=
defaultdict
(
float
)
# float or int?
associations
=
defaultdict
(
float
)
# float or int?
...
@@ -94,11 +117,15 @@ class Node(CTENode):
...
@@ -94,11 +117,15 @@ class Node(CTENode):
ngram
=
ngrams
[
ngram_text
],
ngram
=
ngrams
[
ngram_text
],
weight
=
weight
weight
=
weight
)
)
class
Node_Resource
(
models
.
Model
):
node
=
models
.
ForeignKey
(
Node
,
related_name
=
'node_resource'
)
resource
=
models
.
ForeignKey
(
Resource
)
parsed
=
models
.
BooleanField
(
default
=
False
)
class
Node_Ngram
(
models
.
Model
):
class
Node_Ngram
(
models
.
Model
):
node
=
models
.
ForeignKey
(
Node
,
on_delete
=
models
.
CASCADE
)
node
=
models
.
ForeignKey
(
Node
)
ngram
=
models
.
ForeignKey
(
Ngram
,
on_delete
=
models
.
CASCADE
)
ngram
=
models
.
ForeignKey
(
Ngram
)
weight
=
models
.
IntegerField
()
weight
=
models
.
IntegerField
()
class
Project
(
Node
):
class
Project
(
Node
):
...
...
test-parsing_from_node.py
View file @
c50f2fff
...
@@ -38,6 +38,11 @@ except:
...
@@ -38,6 +38,11 @@ except:
parent
=
corpus
parent
=
corpus
)
.
save
()
)
.
save
()
corpus
.
add_resource
(
file
=
'/path/to/file'
)
corpus
.
parse
()
exit
()
cache
=
Cache
()
cache
=
Cache
()
for
child
in
corpus
.
children
.
all
():
for
child
in
corpus
.
children
.
all
():
print
(
child
.
id
)
print
(
child
.
id
)
...
...
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