<commit_before># -*- coding: utf-8 -*-
"""

Authors:  <NAME> (<EMAIL>)
          <NAME> (<EMAIL>)

Copyright 2014 CSIRO

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

This is a base module for developers to use to create their own modules.

Part of the CWSLab Model Analysis Service VisTrails plugin.

"""

import abc

from vistrails.core.modules import vistrails_module
from vistrails.core.modules import basic_modules

from cwsl.configuration import configuration
from cwsl.core.constraint import Constraint
from cwsl.core.process_unit import ProcessUnit
from cwsl.core.pattern_generator import PatternGenerator


class BaseModule(object):

    __metaclass__ = abc.ABCMeta
    
    # Define the module ports.
    _input_ports = [('in_dataset', 'csiro.au.cwsl:VtDataSet'),
                    ('added_constraints', basic_modules.List, True,
                     {'defaults': ["[]"]})]
    
    _output_ports = [('out_dataset', 'csiro.au.cwsl:VtDataSet'),
                     ('out_constraints', basic_modules.String, True)]
    
    _execution_options = {'required_modules': []}

    _module_setup = {'command': '',
                     'user_authoritative': '',
                     'data_type': ''}
    _positional_args = []
    _added_cons = set([])
    

    def __init__(self):
        
        super(BaseModule, self).__init__()
        
        #Command Line Tool
        tools_base_path = configuration.cwsl_ctools_path
        self.command = self._module_setup['command']
        # Output file structure declaration 
        self.out_pattern = PatternGenerator(self._module_setup['user_authoritative'],
                                            self._module_setup['data_type']).pattern
        
        # Set up the output command for this module, adding extra options.
        self.positional_args = self._positional_args
        
    def compute(self):

        # Required input
        in_dataset = self.getInputFromPort("in_dataset")
        
        new_cons = self._added_cons
        
        # Execute the process.
        this_process = ProcessUnit([in_dataset],
                                   self.out_pattern,
                                   self.command,
                                   cons_for_output,
                                   positional_args=self.positional_args,
                                   execution_options=self._execution_options)

        try:
            this_process.execute(simulate=configuration.simulate_execution)
        except Exception, e:
            raise vistrails_module.ModuleError(self, e.output)

        process_output = this_process.file_creator

        self.setResult('out_dataset', process_output)
<commit_msg>Altered variable name and removed unnecessary extra output port.<commit_after># -*- coding: utf-8 -*-
"""

Authors:  <NAME> (<EMAIL>)
          <NAME> (<EMAIL>)

Copyright 2014 CSIRO

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

This is a base module for developers to use to create their own modules.

Part of the CWSLab Model Analysis Service VisTrails plugin.

"""

import abc

from vistrails.core.modules import vistrails_module
from vistrails.core.modules import basic_modules

from cwsl.configuration import configuration
from cwsl.core.constraint import Constraint
from cwsl.core.process_unit import ProcessUnit
from cwsl.core.pattern_generator import PatternGenerator


class BaseModule(object):
    ''' An abstract class to build your own VisTrails modules. '''

    __metaclass__ = abc.ABCMeta
    
    # Define the module ports.
    _input_ports = [('in_dataset', 'csiro.au.cwsl:VtDataSet'),
                    ('added_constraints', basic_modules.List, True,
                     {'defaults': ["[]"]})]
    
    _output_ports = [('out_dataset', 'csiro.au.cwsl:VtDataSet')]
    
    _execution_options = {'required_modules': []}

    _module_setup = {'command': '',
                     'user_or_authoritative': '',
                     'data_type': ''}
    _positional_args = []
    _added_cons = set([])
    

    def __init__(self):
        
        super(BaseModule, self).__init__()
        
        self.command = self._module_setup['command']
        # Output file structure declaration 
        self.out_pattern = PatternGenerator(self._module_setup['user_or_authoritative'],
                                            self._module_setup['data_type']).pattern
        
        self.positional_args = self._positional_args
        self.execution_options = self._execution_options

        
    def compute(self):


        # Required input
        in_dataset = self.getInputFromPort("in_dataset")
        
        new_cons = self._added_cons
        
        # Execute the process.
        this_process = ProcessUnit([in_dataset],
                                   self.out_pattern,
                                   self.command,
                                   cons_for_output,
                                   positional_args=self.positional_args,
                                   execution_options=self.execution_options)

        try:
            this_process.execute(simulate=configuration.simulate_execution)
        except Exception, e:
            raise vistrails_module.ModuleError(self, e.output)

        process_output = this_process.file_creator

        self.setResult('out_dataset', process_output)

{'fraction_non_alphanumeric': 0.08167489253303614, 'fraction_numerical': 0.0028657857029135486, 'mean_word_length': 2.362955032119914, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4648268', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1623, 'n_words': 458}