<commit_before>#!/usr/bin/env python
# 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.

from StanfordDependencies import StanfordDependencies

if __name__ == "__main__":
    # simple testing script -- ideally will be replaced with proper
    # unit tests
    def print_sentences(sentences):
        for sentence in sentences:
            print '---'
            for token in sentence:
                print token
        print

    for backend in ('jpype', 'subprocess'):
        print 'Backend:', backend
        sd = StanfordDependencies.get_instance(backend=backend)
        sents = sd.convert_trees(['(S1 (NP (DT a) (NN cow)))',
                                  '(S1 (NP (DT some) (NNS cows)))',
                                  '(S1 (NP (DT some) (JJ blue) (NN moose)))'],
                                 representation='basic')
        print_sentences(sents)

        tree = '(S1 (NP (NP (NP (DT A) (NN cat)) (CC and) ' + \
               '(NP (DT a) (NN mouse))) (. .)))'
        for representation in ('basic', 'collapsed', 'CCprocessed',
                               'collapsedTree'):
            print '%s representation' % representation
            print_sentences(sd.convert_trees([tree],
                                             representation=representation))<commit_msg>test.py: move print_sentences outside of __main__<commit_after>#!/usr/bin/env python
# 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.

from StanfordDependencies import StanfordDependencies

def print_sentences(sentences):
    for sentence in sentences:
        print '---'
        for token in sentence:
            print token
    print

if __name__ == "__main__":
    # simple testing script -- ideally will be replaced with proper
    # unit tests

    for backend in ('jpype', 'subprocess'):
        print 'Backend:', backend
        sd = StanfordDependencies.get_instance(backend=backend)
        sents = sd.convert_trees(['(S1 (NP (DT a) (NN cow)))',
                                  '(S1 (NP (DT some) (NNS cows)))',
                                  '(S1 (NP (DT some) (JJ blue) (NN moose)))'],
                                 representation='basic')
        print_sentences(sents)

        tree = '(S1 (NP (NP (NP (DT A) (NN cat)) (CC and) ' + \
               '(NP (DT a) (NN mouse))) (. .)))'
        for representation in ('basic', 'collapsed', 'CCprocessed',
                               'collapsedTree'):
            print '%s representation' % representation
            print_sentences(sd.convert_trees([tree],
                                             representation=representation))
{'fraction_non_alphanumeric': 0.10270722857940273, 'fraction_numerical': 0.004465531677365337, 'mean_word_length': 2.223021582733813, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5497003', 'n_tokens_mistral': 927, 'n_tokens_neox': 887, 'n_words': 352}