Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cloud-consulting
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
cloud-consulting
Commits
809d4c58
Commit
809d4c58
authored
Mar 20, 2016
by
Sebastian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small changes to enable specified answer_set_list on which the learning is based on
parent
a879924c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
22 deletions
+34
-22
bt5/erp5_survey_ml/ExtensionTemplateItem/portal_components/extension.erp5.SurveyMachineLearning.py
...portal_components/extension.erp5.SurveyMachineLearning.py
+32
-21
bt5/erp5_survey_ml/ExtensionTemplateItem/portal_components/extension.erp5.SurveyMachineLearning.xml
...ortal_components/extension.erp5.SurveyMachineLearning.xml
+1
-1
bt5/erp5_survey_ml/bt/test_dependency_list
bt5/erp5_survey_ml/bt/test_dependency_list
+1
-0
No files found.
bt5/erp5_survey_ml/ExtensionTemplateItem/portal_components/extension.erp5.SurveyMachineLearning.py
View file @
809d4c58
...
...
@@ -3,27 +3,33 @@ import nltk
import
numpy
as
np
from
sklearn.feature_extraction.text
import
TfidfVectorizer
from
Products.ERP5Type.Log
import
log
stemmer
=
nltk
.
stem
.
porter
.
PorterStemmer
()
def
stemTokens
(
tokens
):
return
[
stemmer
.
stem
(
item
)
for
item
in
tokens
]
def
Answer_getCorrectionSuggestion
(
self
):
def
Answer_getCorrectionSuggestion
(
self
,
answer_set_list
=
None
,
try_cache
=
True
):
memcached_tool
=
self
.
getPortalObject
().
portal_memcached
memcached_dict
=
memcached_tool
.
getMemcachedDict
(
key_prefix
=
'correctionSuggestion'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
try
:
existing_suggestion
=
memcached_dict
[
self
.
getPath
()]
return
existing_suggestion
except
KeyError
:
pass
def
getCorrectionSuggestion
():
if
try_cache
:
try
:
existing_suggestion
=
memcached_dict
[
self
.
getPath
()]
return
existing_suggestion
except
KeyError
:
pass
else
:
log
(
"Answer_getCorrectionSuggestion without caching!"
)
def
getCorrectionSuggestion
(
answer_set_list
):
question_id
=
str
(
self
.
getResourceId
())
portal
=
self
.
getPortalObject
()
answer_set_list
=
portal
.
portal_catalog
(
portal_type
=
"Answer Set"
,
validation_state
=
"archived"
,
version
=
"001"
)
if
answer_set_list
is
None
:
log
(
"Answer_getCorrectionSuggestion without trainingsdata!"
)
answer_set_list
=
portal
.
portal_catalog
(
portal_type
=
"Answer Set"
,
validation_state
=
"archived"
,
version
=
"001"
)
## Get ALL the data from ERP and process within this cell so other cells do not depend on the ERP interface
# this is due to ERP being slightly unstable and causing trouble
...
...
@@ -90,32 +96,37 @@ def Answer_getCorrectionSuggestion(self):
# Caching. Does not permanetly cache so not used anymore
#getCorrectionSuggestion = CachingMethod(getCorrectionSuggestion, "getCorrectionSuggestion@" + self.getPath())
#return getCorrectionSuggestion()
correctionSuggestion
=
getCorrectionSuggestion
()
correctionSuggestion
=
getCorrectionSuggestion
(
answer_set_list
)
memcached_dict
[
self
.
getPath
()]
=
correctionSuggestion
return
correctionSuggestion
# returns a dict with similar, suggested configurations to the Answer Set this method is called on
# the format of the returned dict is given by the Javascript processing it
def
AnswerSet_getSuggestionExampleData
(
self
):
def
AnswerSet_getSuggestionExampleData
(
self
,
answer_set_list
=
None
,
try_cache
=
True
):
memcached_tool
=
self
.
getPortalObject
().
portal_memcached
memcached_dict
=
memcached_tool
.
getMemcachedDict
(
key_prefix
=
'correctionSuggestion'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
try
:
existing_suggestion
=
memcached_dict
[
self
.
getPath
()]
return
existing_suggestion
except
KeyError
:
pass
if
try_cache
:
try
:
existing_suggestion
=
memcached_dict
[
self
.
getPath
()]
return
existing_suggestion
except
KeyError
:
pass
else
:
log
(
"Answer_getSuggestionExampleData without caching!"
)
def
getSuggestionExampleData
():
def
getSuggestionExampleData
(
answer_set_list
):
portal
=
self
.
getPortalObject
()
answer_set_module
=
portal
.
answer_set_module
new_answer_set
=
(
self
.
getId
(),
getTextBlob
(
self
))
answer_set_list
=
self
.
portal_catalog
(
portal_type
=
"Answer Set"
,
validation_state
=
"released"
)
if
answer_set_list
is
None
:
answer_set_list
=
self
.
portal_catalog
(
portal_type
=
"Answer Set"
,
validation_state
=
"released"
)
answer_set_list_tb
=
[(
a
.
getId
(),
getTextBlob
(
a
))
for
a
in
answer_set_list
]
scoring_list
=
rateSimilarity
(
new_answer_set
,
answer_set_list_tb
)[
1
:]
## for testing:
...
...
@@ -177,7 +188,7 @@ def AnswerSet_getSuggestionExampleData(self):
#getSuggestionExampleData = CachingMethod(getSuggestionExampleData, "getSuggestionExampleData@" + self.getPath())
#return getSuggestionExampleData()
exampleSuggestion
=
getSuggestionExampleData
()
exampleSuggestion
=
getSuggestionExampleData
(
answer_set_list
)
memcached_dict
[
self
.
getPath
()]
=
exampleSuggestion
return
exampleSuggestion
...
...
bt5/erp5_survey_ml/ExtensionTemplateItem/portal_components/extension.erp5.SurveyMachineLearning.xml
View file @
809d4c58
...
...
@@ -46,7 +46,7 @@
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<tuple>
<string>
W:
35
, 4: Unused variable \'example_answer\' (unused-variable)
</string>
<string>
W:
41
, 4: Unused variable \'example_answer\' (unused-variable)
</string>
</tuple>
</value>
</item>
...
...
bt5/erp5_survey_ml/bt/test_dependency_list
0 → 100644
View file @
809d4c58
erp5_survey_ml_test
\ No newline at end of file
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