-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/palavras full output #157
Merged
turicas
merged 5 commits into
NAMD:develop
from
flavioamieiro:feature/palavras_full_output
Oct 21, 2013
+142
−34
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2836f4
Adds worker to store raw output from PALAVRAS
flavioamieiro 1af2a8e
Adapts portuguese POS tagger to use palavras output previously stored
flavioamieiro dfe4718
Returns an empty list instead of None if palavras_raw is not available
flavioamieiro d3d1fd4
Updates test to account for the last change
flavioamieiro b5133c6
Adds PalavrasRaw to available workers
flavioamieiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# coding: utf-8 | ||
# | ||
# Copyright 2012 NAMD-EMAP-FGV | ||
# | ||
# This file is part of PyPLN. You can get more information at: http://pypln.org/. | ||
# | ||
# PyPLN is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# PyPLN is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with PyPLN. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
|
||
from pypelinin import Worker | ||
|
||
|
||
PALAVRAS_ENCODING = sys.getfilesystemencoding() | ||
BASE_PARSER = '/opt/palavras/por.pl' | ||
PARSER_MODE = '--dep' | ||
|
||
def palavras_installed(): | ||
return os.path.exists(BASE_PARSER) | ||
|
||
class PalavrasRaw(Worker): | ||
requires = ['text', 'language'] | ||
|
||
def process(self, document): | ||
if document['language'] != 'pt' or not palavras_installed(): | ||
return {} | ||
|
||
text = document['text'] | ||
process = subprocess.Popen([BASE_PARSER, PARSER_MODE], | ||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE) | ||
stdout, stderr = process.communicate(text.encode(PALAVRAS_ENCODING)) | ||
|
||
return {'palavras_raw': stdout} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# coding: utf-8 | ||
# | ||
# Copyright 2012 NAMD-EMAP-FGV | ||
# | ||
# This file is part of PyPLN. You can get more information at: http://pypln.org/. | ||
# | ||
# PyPLN is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# PyPLN is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with PyPLN. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import unittest | ||
|
||
from textwrap import dedent | ||
|
||
from pypln.backend.workers import palavras_raw | ||
|
||
|
||
ORIGINAL_PATH = palavras_raw.BASE_PARSER | ||
|
||
class TestPalavrasRawWorker(unittest.TestCase): | ||
|
||
def test_should_run_only_if_language_is_portuguese(self): | ||
if palavras_raw.palavras_installed(): | ||
document = {'text': 'There was a rock on the way.', 'language': 'en'} | ||
result = palavras_raw.PalavrasRaw().process(document) | ||
self.assertEqual(result, {}) | ||
|
||
def test_palavras_not_installed(self): | ||
palavras_raw.BASE_PARSER = '/not-found' | ||
document = {'text': 'Tinha uma pedra no meio do caminho.', 'language': 'pt'} | ||
result = palavras_raw.PalavrasRaw().process(document) | ||
self.assertEqual(result, {}) | ||
|
||
|
||
def test_palavras_should_return_raw_if_it_is_installed(self): | ||
palavras_raw.BASE_PARSER = ORIGINAL_PATH | ||
document = {'text': 'Eu sei que neste momento falo para todo Brasil.', | ||
'language': 'pt'} | ||
expected_raw = dedent(''' | ||
Eu [eu] <*> PERS M/F 1S NOM @SUBJ> #1->2 | ||
sei [saber] <fmc> <mv> V PR 1S IND VFIN @FS-STA #2->0 | ||
que [que] <clb> <clb-fs> KS @SUB #3->7 | ||
em [em] <sam-> PRP @PIV> #4->7 | ||
este [este] <-sam> <dem> DET M S @>N #5->6 | ||
momento [momento] <dur> <f-q> N M S @P< #6->4 | ||
falo [falar] <vH> <mv> V PR 1S IND VFIN @FS-<ACC #7->2 | ||
para [para] PRP @<ADVL #8->7 | ||
todo [todo] <quant> DET M S @>N #9->10 | ||
Brasil [Brasil] <civ> <newlex> <*> PROP M S @P< [Brasil] <*> PROP M S @P< #10->8 | ||
$. #11->0 | ||
</s> | ||
''').strip() + '\n\n' | ||
result = palavras_raw.PalavrasRaw().process(document) | ||
expected_result = {'palavras_raw': expected_raw} | ||
self.assertEqual(expected_result, result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is failing!