Пример #1
0
    def test_for_nlpnet(self):
        """
        Attempting to use nlpnet. This will cause an
        error if the required dependencies are not
        downloaded.
        """

        try:
            # Creating a new compare object
            compare_nlpnet = Compare()

            # Comparing using the nltk parser
            compare_nlpnet.compare_strings(
                text=["what time is it here?", "This is the cat's hat"],
                pattern_detection=False,
                parser="nlpnet")

            # If that was successfuly, getting information
            sentence_information = compare_nlpnet.get_pattern_information()
            for sentence in sentence_information:
                my_pattern = "[ Pattern ]          : " + sentence.pattern
                my_subject = "[ Subject ]          : " + sentence.subject
                my_verb = "[ Verb ]             : " + sentence.verb
                my_object = "[ Object ]           : " + sentence.object[0]
                my_preps = "[ Prep Phrases ]     : " + str(
                    sentence.prepositional_phrases)
                my_reliability_score = "[ Reliability Score ]: " + str(
                    sentence.reliability_score)
        except:
            # Getting nltk data path
            running = Popen(['python -c "import nltk;print nltk.data.path"'],
                            stdin=PIPE,
                            stdout=PIPE,
                            stderr=PIPE,
                            shell=True)
            stdin, stdout = running.communicate()

            # Setting the path that the nlpnet dependency will be downloaded from
            path = re.sub(
                r"\'", "",
                re.sub(r"\[", '', str(stdin.split('\n')[0].split(',')[0])))
            path = path.split(r"/")
            path = '/'.join(path[0:len(path) - 1]) + '/nlpnet_dependency/'

            # Download the dependencies & extract
            current_directory = os.getcwd()

            os.mkdir(path)
            os.chdir(path)

            os.system(
                "wget http://nilc.icmc.usp.br/nlpnet/data/dependency-en.tgz")
            tar = tarfile.open(path + 'dependency-en.tgz', 'r:gz')
            tar.extractall(path)
            os.remove(path + 'dependency-en.tgz')

            os.chdir(current_directory)
Пример #2
0
class regex4dummies:
    # Setting global version variable which contains the version of this library
    __version__ = '1.4.6'

    def __init__(self, **kwargs):
        """
        Constructor method.
        """

        # Testing the system to make sure all dependencies are installed
        RunDependencyTests()

        # Instantiating compare object to be used
        self.compare_object = Compare()

    def compare_strings(self, **kwargs):
        """
        Function that is integral in communicating between a compare object and the user
        This function returns a 3-tuple array containing reliability score, applicability score, and pattern
        """

        # Call compare_strings of compare object & return output
        if kwargs.get("pattern_detection") == "literal":
            return self.compare_object.compare_strings(
                text=kwargs.get("text"),
                pattern_detection=True,
                parser=kwargs.get("parser"))
        else:
            return self.compare_object.compare_strings(
                text=kwargs.get("text"),
                pattern_detection=False,
                parser=kwargs.get("parser"))

    def get_pattern_information(self):
        """
        This function returns the information for each sentence/pattern that was identified.
        This is only useful if semantic parsing is implemented; otherwise, {} will be returned.
        """

        return self.compare_object.get_pattern_information()

    def get_topics(self, **kwargs):
        """ Returns the list of topics that the parsers identified """

        return self.compare_object.get_pattern_topics(kwargs.get("text"))

    def extract_important_information(self, **kwargs):
        """
        Returns the important information within the given text.
        """

        return self.compare_object.extract_important_information(
            kwargs.get("text"))
Пример #3
0
class regex4dummies:
    # Setting global version variable which contains the version of this library
    __version__ = '1.4.6'

    def __init__(self, **kwargs):
        """
        Constructor method.
        """

        # Testing the system to make sure all dependencies are installed
        RunDependencyTests()

        # Instantiating compare object to be used
        self.compare_object = Compare()

    def compare_strings(self, **kwargs):
        """
        Function that is integral in communicating between a compare object and the user
        This function returns a 3-tuple array containing reliability score, applicability score, and pattern
        """

        # Call compare_strings of compare object & return output
        if kwargs.get("pattern_detection") == "literal":
            return self.compare_object.compare_strings(text=kwargs.get("text"), pattern_detection=True, parser=kwargs.get("parser"))
        else:
            return self.compare_object.compare_strings(text=kwargs.get("text"), pattern_detection=False, parser=kwargs.get("parser"))

    def get_pattern_information( self ):
        """
        This function returns the information for each sentence/pattern that was identified.
        This is only useful if semantic parsing is implemented; otherwise, {} will be returned.
        """

        return self.compare_object.get_pattern_information()

    def get_topics(self, **kwargs):
        """ Returns the list of topics that the parsers identified """

        return self.compare_object.get_pattern_topics(kwargs.get("text"))

    def extract_important_information(self, **kwargs):
        """
        Returns the important information within the given text.
        """

        return self.compare_object.extract_important_information(kwargs.get("text"))
    def test_for_nlpnet(self):
        """
        Attempting to use nlpnet. This will cause an
        error if the required dependencies are not
        downloaded.
        """

        try:
            # Creating a new compare object
            compare_nlpnet = Compare()

            # Comparing using the nltk parser
            compare_nlpnet.compare_strings(text=["what time is it here?", "This is the cat's hat"], pattern_detection=False, parser="nlpnet")

            # If that was successfuly, getting information
            sentence_information = compare_nlpnet.get_pattern_information()
            for sentence in sentence_information:
                my_pattern = "[ Pattern ]          : " + sentence.pattern
                my_subject = "[ Subject ]          : " + sentence.subject
                my_verb = "[ Verb ]             : " + sentence.verb
                my_object = "[ Object ]           : " + sentence.object[0]
                my_preps = "[ Prep Phrases ]     : " + str(sentence.prepositional_phrases)
                my_reliability_score = "[ Reliability Score ]: " + str(sentence.reliability_score)
        except:
            # Getting nltk data path
            running = Popen(['python -c "import nltk;print nltk.data.path"'], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
            stdin, stdout = running.communicate()

            # Setting the path that the nlpnet dependency will be downloaded from
            path = re.sub(r"\'", "", re.sub(r"\[", '', str(stdin.split('\n')[0].split(',')[0])))
            path = path.split(r"/")
            path = '/'.join(path[0 : len(path) - 1]) + '/nlpnet_dependency/'

            # Download the dependencies & extract
            current_directory = os.getcwd()

            os.mkdir(path)
            os.chdir(path)

            os.system("wget http://nilc.icmc.usp.br/nlpnet/data/dependency-en.tgz")
            tar = tarfile.open(path + 'dependency-en.tgz', 'r:gz')
            tar.extractall(path)
            os.remove(path + 'dependency-en.tgz')

            os.chdir(current_directory)