# Path: pennpipeline.py
# class PennPipeline(object):
#     """Provide access to a pipeline of NLP tools."""
# 
#     def __init__(self):
#         # Set up the pipes
#         self.tag_proc, self.parse_proc, self.ecrestore_proc = (None, None, None)
#         self.tag_proc = _setup_pipe(TAGGER)
#         self.parse_proc = _setup_pipe(PARSER)
#         self.ecrestore_proc = _setup_pipe(ECRESTORER, ECRESTORER_DIR)
# 
#     def __del__(self):
#         """Terminate all pipelines."""
#         # This is possibly unnecessary, but doesn't do any harm.
#         for proc in (self.tag_proc, self.parse_proc, self.ecrestore_proc):
#             _terminate_with_extreme_prejudice(proc)
# 
#     def parse_text(self, text, force_nouns=None, force_verbs=None, correct_punc=True,
#                    verbose=False):
#         """Run the text through the pipelines."""
#         # Check for empty text
#         if not text:
#             return ""
# 
#         # Replace any newlines or carriage returns with space
#         text = text.replace('\n', ' ')
#         text = text.replace('\r', ' ')
# 
#         # Create default set arguments
#         if not force_nouns:
#             force_nouns = set()
#         if not force_verbs:
#             force_verbs = set()
# 
#         # Add in final punctuation if it's missing
#         if correct_punc and text[-1] not in ('.', '?', '!'):
#             text += '.'
# 
#         # TODO: Deal with multiple sentences
#         try:
#             tagged_sent = _process_pipe_filter(text, self.tag_proc, read_until_empty=True)
#         except IOError:
#             raise IOError("Tagger process has died. Make sure that the command\n{}\ncan "
#                           "be run successfully.".format(TAGGER))
#         if verbose:
#             # Show the tags without any forced tags
#             display_tagged_sent = _tag_convert(tagged_sent, set(), set())
#             print "Original tags:"
#             print display_tagged_sent
#         clean_tagged_sent = _tag_convert(tagged_sent, force_nouns, force_verbs)
#         if verbose and (force_nouns or force_verbs) and (clean_tagged_sent != display_tagged_sent):
#             print "Modified tags:"
#             print clean_tagged_sent
#         try:
#             parsed_sent = _process_pipe_filter(clean_tagged_sent, self.parse_proc, "(")
#         except IOError:
#             raise IOError("Parser process has died. Make sure that the command\n{}\ncan "
#                           "be run successfully.".format(PARSER))
#         # Wrap input to the null restorer as ( x) exactly as wrap-stream.pl used to do
#         try:
#             restored_sent = _process_pipe_filter("( " + parsed_sent + ")", self.ecrestore_proc, "(")
#         except IOError:
#             raise IOError("ECRestorer process has died. Make sure that the command\n{}\ncan "
#                           "be run successfully in the {} directory.".format(ECRESTORER, ECRESTORER_DIR))
# 
#         # Remove extra parens from the parse with elements restored
#         final_parse = OUTER_PARENS_RE.match(restored_sent).group(1)
# 
#         return final_parse


import roslib
import rospy
import sys
import os
from nlp.srv import String
from pennpipeline import PennPipeline
#
# This file is a part of SLURP.
#
# SLURP 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.
# 
# SLURP 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 SLURP.  If not, see <http://www.gnu.org/licenses/>.

roslib.load_manifest('nlp')

# Get slurp into the sys.path
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(MODULE_DIR, '..', '..', '..'))


NODE_NAME = "penn_nlp_pipeline_server"
SERVICE_NAME = "penn_nlp_pipeline_service"

class PipelineService():
    """Provides a connection to the pipeline via a ROS service."""
    
    def __init__(self):

# Path: pennpipeline.py
# class PennPipeline(object):
#     """Provide access to a pipeline of NLP tools."""
# 
#     def __init__(self):
#         # Set up the pipes
#         self.tag_proc, self.parse_proc, self.ecrestore_proc = (None, None, None)
#         self.tag_proc = _setup_pipe(TAGGER)
#         self.parse_proc = _setup_pipe(PARSER)
#         self.ecrestore_proc = _setup_pipe(ECRESTORER, ECRESTORER_DIR)
# 
#     def __del__(self):
#         """Terminate all pipelines."""
#         # This is possibly unnecessary, but doesn't do any harm.
#         for proc in (self.tag_proc, self.parse_proc, self.ecrestore_proc):
#             _terminate_with_extreme_prejudice(proc)
# 
#     def parse_text(self, text, force_nouns=None, force_verbs=None, correct_punc=True,
#                    verbose=False):
#         """Run the text through the pipelines."""
#         # Check for empty text
#         if not text:
#             return ""
# 
#         # Replace any newlines or carriage returns with space
#         text = text.replace('\n', ' ')
#         text = text.replace('\r', ' ')
# 
#         # Create default set arguments
#         if not force_nouns:
#             force_nouns = set()
#         if not force_verbs:
#             force_verbs = set()
# 
#         # Add in final punctuation if it's missing
#         if correct_punc and text[-1] not in ('.', '?', '!'):
#             text += '.'
# 
#         # TODO: Deal with multiple sentences
#         try:
#             tagged_sent = _process_pipe_filter(text, self.tag_proc, read_until_empty=True)
#         except IOError:
#             raise IOError("Tagger process has died. Make sure that the command\n{}\ncan "
#                           "be run successfully.".format(TAGGER))
#         if verbose:
#             # Show the tags without any forced tags
#             display_tagged_sent = _tag_convert(tagged_sent, set(), set())
#             print "Original tags:"
#             print display_tagged_sent
#         clean_tagged_sent = _tag_convert(tagged_sent, force_nouns, force_verbs)
#         if verbose and (force_nouns or force_verbs) and (clean_tagged_sent != display_tagged_sent):
#             print "Modified tags:"
#             print clean_tagged_sent
#         try:
#             parsed_sent = _process_pipe_filter(clean_tagged_sent, self.parse_proc, "(")
#         except IOError:
#             raise IOError("Parser process has died. Make sure that the command\n{}\ncan "
#                           "be run successfully.".format(PARSER))
#         # Wrap input to the null restorer as ( x) exactly as wrap-stream.pl used to do
#         try:
#             restored_sent = _process_pipe_filter("( " + parsed_sent + ")", self.ecrestore_proc, "(")
#         except IOError:
#             raise IOError("ECRestorer process has died. Make sure that the command\n{}\ncan "
#                           "be run successfully in the {} directory.".format(ECRESTORER, ECRESTORER_DIR))
# 
#         # Remove extra parens from the parse with elements restored
#         final_parse = OUTER_PARENS_RE.match(restored_sent).group(1)
# 
#         return final_parse


# Path: ros/nlp/src/pipelineservice.py
import roslib
import rospy
import sys
import os
from nlp.srv import String
from pennpipeline import PennPipeline

#
# This file is a part of SLURP.
#
# SLURP 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.
# 
# SLURP 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 SLURP.  If not, see <http://www.gnu.org/licenses/>.

roslib.load_manifest('nlp')

# Get slurp into the sys.path
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(MODULE_DIR, '..', '..', '..'))


NODE_NAME = "penn_nlp_pipeline_server"
SERVICE_NAME = "penn_nlp_pipeline_service"

class PipelineService():
    """Provides a connection to the pipeline via a ROS service."""
    
    def __init__(self):

        self._pipeline = PennPipeline()