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
4381e35a
Commit
4381e35a
authored
Oct 16, 2014
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started working on the ngrams extractors.
Changed the models a little.
parent
db5a17ce
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
0 deletions
+69
-0
EnglishNgramsExtractor.py
mat-parsing/NgramsExtractors/EnglishNgramsExtractor.py
+6
-0
FrenchNgramsExtractor.py
mat-parsing/NgramsExtractors/FrenchNgramsExtractor.py
+6
-0
NgramsExtractor.py
mat-parsing/NgramsExtractors/NgramsExtractor.py
+23
-0
__init__.py
mat-parsing/NgramsExtractors/__init__.py
+2
-0
models.py
node/models.py
+32
-0
No files found.
mat-parsing/NgramsExtractors/EnglishNgramsExtractor.py
0 → 100644
View file @
4381e35a
from
NgramsExtractor
import
NgramsExtractor
class
EnglishNgramsExtractor
(
NgramsExtractor
):
pass
\ No newline at end of file
mat-parsing/NgramsExtractors/FrenchNgramsExtractor.py
0 → 100644
View file @
4381e35a
from
NgramsExtractor
import
NgramsExtractor
class
FrenchNgramsExtractor
(
NgramsExtractor
):
pass
\ No newline at end of file
mat-parsing/NgramsExtractors/NgramsExtractor.py
0 → 100644
View file @
4381e35a
"""Base class for all ngrams extractors.
"""
class
NgramsExtractor
:
"""Class instanciation.
This method can be overriden.
"""
def
__init__
(
self
):
pass
def
tag_ngrams
(
self
,
contents
):
return
[]
"""Extracts a list of ngrams.
Returns a list of the ngrams found in the given text.
"""
def
extract_ngrams
(
self
,
contents
):
tagged_ngrams
=
self
.
tag_ngrams
()
\ No newline at end of file
mat-parsing/NgramsExtractors/__init__.py
0 → 100644
View file @
4381e35a
from
FrenchNgramsExtractor
import
FrenchNgramsExtractor
from
EnglishNgramsExtractor
import
EnglishNgramsExtractor
\ No newline at end of file
node/models.py
View file @
4381e35a
...
...
@@ -9,6 +9,8 @@ from time import time
from
django.contrib.auth.models
import
User
from
language
import
Language
from
collections
import
defaultdict
def
upload_to
(
instance
,
filename
):
return
'corpora/
%
s/
%
f/
%
s'
%
(
instance
.
user
.
username
,
time
(),
filename
)
...
...
@@ -24,8 +26,38 @@ class Language(models.Model):
class
Ngram
(
models
.
Model
):
language
=
models
.
ForeignKey
(
Language
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
SET_NULL
)
n
=
models
.
IntegerField
()
terms
=
models
.
CharField
(
max_length
=
255
)
class
class
Ngram_Cache
:
def
__init__
(
self
,
language
):
self
.
_language_id
=
{}
self
.
_ngram_ids
=
[]
# get the language id
language
=
language
.
lower
()
if
len
(
language
)
==
"3"
:
self
.
_language_id
=
Language
.
get
(
iso3
=
language
)
.
id
elif
len
(
language
)
==
"2"
:
self
.
_language_id
=
Language
.
get
(
iso2
=
language
)
.
id
else
:
import
pycountry
pycountry
.
languages
.
get
(
alpha2
=
'an'
)
def
get
(
self
,
language
,
terms
):
# get the term id
terms
=
terms
.
strip
()
.
lower
()
if
terms
not
in
self
.
_cache
[
language
]:
try
:
ngram
=
NGram
.
get
(
terms
=
terms
)
except
:
ngram
=
NGram
(
terms
=
terms
,
n
=
len
(
terms
),
language_id
=
self
.
_language_id
)
ngram
.
save
()
self
.
_cache
[
language
][
terms
]
=
ngram
.
pk
# return the term id
return
self
.
_cache
[
language
][
terms
]
class
Resource
(
models
.
Model
):
...
...
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