コード例 #1
0
ファイル: test.py プロジェクト: BLLIP/bllip-parser
def test_extpos():
    sr1 = parser.SentRep(['record'])

    print 'Unconstrained'
    display_parses(parser.parse(sr1))

    print 'NN'
    ext_pos1 = parser.ExtPos()
    ext_pos1.addTagConstraints(parser.StringVector(['NN']))

    display_parses(parser.parse(sr1, ext_pos1, None))

    print 'VB'
    ext_pos2 = parser.ExtPos()
    ext_pos2.addTagConstraints(parser.StringVector(['VB']))
    display_parses(parser.parse(sr1, ext_pos2, None))
コード例 #2
0
def test_extpos():
    sr1 = parser.SentRep(['record'])

    print 'Unconstrained'
    display_parses(parser.parse(sr1, thread_slot))

    print 'NN'
    ext_pos1 = parser.ExtPos()
    ext_pos1.addTagConstraints(parser.VectorString(['NN']))

    display_parses(parser.parse(sr1, ext_pos1, thread_slot))

    print 'VB'
    ext_pos2 = parser.ExtPos()
    ext_pos2.addTagConstraints(parser.VectorString(['VB']))
    display_parses(parser.parse(sr1, ext_pos2, thread_slot))
コード例 #3
0
ファイル: test.py プロジェクト: KerstenDoering/CPI-Pipeline
def test_extpos():
    sr1 = parser.SentRep(["record"])

    print "Unconstrained"
    display_parses(parser.parse(sr1))

    print "NN"
    ext_pos1 = parser.ExtPos()
    ext_pos1.addTagConstraints(parser.StringVector(["NN"]))

    display_parses(parser.parse(sr1, ext_pos1))

    print "VB"
    ext_pos2 = parser.ExtPos()
    ext_pos2.addTagConstraints(parser.StringVector(["VB"]))
    display_parses(parser.parse(sr1, ext_pos2))
コード例 #4
0
def test_parse():
    sr1 = parser.SentRep(['These', 'are', 'tokens', '.'])
    sr2 = test_tokenizer()

    for sr in (sr1, sr2):
        parses = parser.parse(sr, thread_slot)
        display_parses(parses)
        print '---'
コード例 #5
0
ファイル: test.py プロジェクト: KerstenDoering/CPI-Pipeline
def test_parse():
    sr1 = parser.SentRep(["These", "are", "tokens", "."])
    sr2 = test_tokenizer()

    for sr in (sr1, sr2):
        parses = parser.parse(sr)
        display_parses(parses)
        print "---"
コード例 #6
0
ファイル: test.py プロジェクト: BLLIP/bllip-parser
def test_parse():
    sr1 = parser.SentRep(['These', 'are', 'tokens', '.'])
    sr2 = test_tokenizer()

    for sr in (sr1, sr2):
        parses = parser.parse(sr)
        display_parses(parses)
        print '---'
コード例 #7
0
    def parse(self, sentence, rerank=True, max_sentence_length=399):
        """Parse some text or tokens and return an NBestList with the
        results.  sentence can be a string or a sequence.  If it is a
        string, it will be tokenized.  If rerank is True, we will rerank
        the n-best list."""
        assert self._parser_model_loaded

        sentence = Sentence(sentence, max_sentence_length)
        parses = parser.parse(sentence.sentrep, self._parser_thread_slot)
        nbest_list = NBestList(sentence, parses)
        if rerank:
            self.rerank(nbest_list)
        return nbest_list
コード例 #8
0
ファイル: test.py プロジェクト: BLLIP/bllip-parser
def test_multiword_extpos():
    sr1 = parser.SentRep('British left waffles on Falklands .'.split())

    print 'waffles = [anything]:'
    display_parses(parser.parse(sr1))

    if 1:
        print 'waffles = VBZ/VBD/VB:'
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector(['VBZ', 'VBD', 'VB']))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        display_parses(parser.parse(sr1, ext_pos, None))

        print 'waffles = NNS:'
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector(['NNS']))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        display_parses(parser.parse(sr1, ext_pos, None))

        print 'waffles = NN/NNS:'
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector(['NN', 'NNS']))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        display_parses(parser.parse(sr1, ext_pos, None))
コード例 #9
0
ファイル: test.py プロジェクト: KerstenDoering/CPI-Pipeline
def test_multiword_extpos():
    sr1 = parser.SentRep("British left waffles on Falklands .".split())

    print "waffles = [anything]:"
    display_parses(parser.parse(sr1))

    if 1:
        print "waffles = VBZ/VBD/VB:"
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector(["VBZ", "VBD", "VB"]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        display_parses(parser.parse(sr1, ext_pos))

        print "waffles = NNS:"
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector(["NNS"]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        display_parses(parser.parse(sr1, ext_pos))

        print "waffles = NN/NNS:"
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector(["NN", "NNS"]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        ext_pos.addTagConstraints(parser.StringVector([]))
        display_parses(parser.parse(sr1, ext_pos))
コード例 #10
0
def test_multiword_extpos():
    sr1 = parser.SentRep('British left waffles on Falklands .'.split())

    print 'waffles = [anything]:'
    display_parses(parser.parse(sr1, thread_slot))

    if 1:
        print 'waffles = VBZ/VBD/VB:'
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString(['VBZ', 'VBD', 'VB']))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        display_parses(parser.parse(sr1, ext_pos, thread_slot))

        print 'waffles = NNS:'
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString(['NNS']))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        display_parses(parser.parse(sr1, ext_pos, thread_slot))

        print 'waffles = NN/NNS:'
        ext_pos = parser.ExtPos()
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString(['NN', 'NNS']))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        ext_pos.addTagConstraints(parser.VectorString([]))
        display_parses(parser.parse(sr1, ext_pos, thread_slot))
コード例 #11
0
    def parse(self, sentence, rerank=True, max_sentence_length=399):
        """Parse some text or tokens and return an NBestList with the
        results.  sentence can be a string or a sequence.  If it is a
        string, it will be tokenized.  If rerank is True, we will rerank
        the n-best list."""
        assert self._parser_model_loaded

        sentence = Sentence(sentence, max_sentence_length)
        try:
            parses = parser.parse(sentence.sentrep, self._parser_thread_slot)
        except RuntimeError:
            parses = []
        nbest_list = NBestList(sentence, parses)
        if rerank:
            nbest_list.rerank(self)
        return nbest_list
コード例 #12
0
    def parse_tagged(self, tokens, possible_tags, rerank=True):
        """Parse some pre-tagged, pre-tokenized text.  tokens is a
        sequence of strings.  possible_tags is map from token indices
        to possible POS tags.  Tokens without an entry in possible_tags
        will be unconstrained by POS.  If rerank is True, we will
        rerank the n-best list."""
        assert self._parser_model_loaded

        ext_pos = parser.ExtPos()
        for index in range(len(tokens)):
            tags = possible_tags.get(index, [])
            if isinstance(tags, basestring):
                tags = [tags]
            ext_pos.addTagConstraints(parser.VectorString(tags))

        sentence = Sentence(tokens)
        parses = parser.parse(sentence.sentrep, ext_pos, self._parser_thread_slot)
        nbest_list = NBestList(sentence, parses)
        if rerank:
            nbest_list.rerank(self)
        return nbest_list
コード例 #13
0
    def parse_tagged(self, tokens, possible_tags, rerank=True):
        """Parse some pre-tagged, pre-tokenized text.  tokens is a
        sequence of strings.  possible_tags is map from token indices
        to possible POS tags.  Tokens without an entry in possible_tags
        will be unconstrained by POS.  If rerank is True, we will
        rerank the n-best list."""
        assert self._parser_model_loaded

        ext_pos = parser.ExtPos()
        for index in range(len(tokens)):
            tags = possible_tags.get(index, [])
            if isinstance(tags, basestring):
                tags = [tags]
            ext_pos.addTagConstraints(parser.VectorString(tags))

        sentence = Sentence(tokens)
        parses = parser.parse(sentence.sentrep, ext_pos,
                              self._parser_thread_slot)
        nbest_list = NBestList(sentence, parses)
        if rerank:
            self.rerank(nbest_list)
        return nbest_list
コード例 #14
0
ファイル: burnin.py プロジェクト: malcolmgreaves/BC5CIDTask
#
#     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.

import SWIGParser
import fileinput

if __name__ == "__main__":
    from test import initialize, display_parses
    initialize(n=50)
    for line in fileinput.input():
        line = line.strip()

        print line
        tree = SWIGParser.inputTreeFromString('(S1 ' + line + ')')
        print tree
        sentence = tree.toSentRep()
        print sentence
        parses = SWIGParser.parse(sentence)
        print len(parses), 'parses'
        if not parses:
            raise 'failed'
        display_parses(parses)
        print 'example failure tree', sentence.makeFailureTree('Xyz')
        print
コード例 #15
0
ファイル: test.py プロジェクト: BLLIP/bllip-parser
def test_as_nbest_list():
    sr1 = parser.SentRep(['These', 'are', 'tokens', '.'])
    parses = parser.parse(sr1)
    print parser.asNBestList(parses, 'test_as_nbest_list_sentence')
コード例 #16
0
def test_as_nbest_list():
    sr1 = parser.SentRep(['These', 'are', 'tokens', '.'])
    parses = parser.parse(sr1)
    print parser.asNBestList(parses, 'test_as_nbest_list_sentence')
コード例 #17
0
def test_as_nbest_list():
    sr1 = parser.SentRep(['These', 'are', 'tokens', '.'])
    parses = parser.parse(sr1, thread_slot)
    print parser.asNBestList(parses)
コード例 #18
0
ファイル: test.py プロジェクト: KerstenDoering/CPI-Pipeline
def test_as_nbest_list():
    sr1 = parser.SentRep(["These", "are", "tokens", "."])
    parses = parser.parse(sr1)
    print parser.asNBestList(parses, "test_as_nbest_list_sentence")
コード例 #19
0
ファイル: test.py プロジェクト: lixiangnlp/bllip-parser
def test_as_nbest_list():
    sr1 = parser.SentRep(['These', 'are', 'tokens', '.'])
    parses = parser.parse(sr1, thread_slot)
    print parser.asNBestList(parses)
コード例 #20
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.

import SWIGParser
import fileinput

if __name__ == "__main__":
    from test import initialize, display_parses
    thread_slot = SWIGParser.ThreadSlot()
    initialize(n=50)
    for line in fileinput.input():
        line = line.strip()

        print line
        tree = SWIGParser.inputTreeFromString('(S1 ' + line + ')')
        print tree
        sentence = tree.toSentRep()
        print sentence
        parses = SWIGParser.parse(sentence, thread_slot)
        print len(parses), 'parses'
        if not parses:
            raise 'failed'
        display_parses(parses)
        print 'example failure tree', sentence.makeFailureTree(
            'Xyz', thread_slot)
        print
コード例 #21
0
ファイル: burnin.py プロジェクト: filannim/bllip-parser
#     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.

import SWIGParser
import fileinput

if __name__ == "__main__":
    from test import initialize, display_parses
    thread_slot = SWIGParser.ThreadSlot()
    initialize(n=50)
    for line in fileinput.input():
        line = line.strip()

        print line
        tree = SWIGParser.inputTreeFromString('(S1 ' + line + ')')
        print tree
        sentence = tree.toSentRep()
        print sentence
        parses = SWIGParser.parse(sentence, thread_slot)
        print len(parses), 'parses'
        if not parses:
            raise 'failed'
        display_parses(parses)
        print 'example failure tree', sentence.makeFailureTree('Xyz', thread_slot)
        print