Mercurial > hg > chourdakisreiss2018dmrn
annotate clausiepy/problog/clausiepy_pl.py @ 1:2082aeb1f1be tip
added demo and readme file
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Wed, 19 Dec 2018 06:51:16 +0000 |
parents | |
children |
rev | line source |
---|---|
e@1 | 1 #!/usr/bin/env python3 |
e@1 | 2 # -*- coding: utf-8 -*- |
e@1 | 3 """ |
e@1 | 4 Created on Wed Sep 26 13:38:38 2018 |
e@1 | 5 |
e@1 | 6 @author: Emmanouil Theofanis Chourdakis |
e@1 | 7 |
e@1 | 8 Problog module for extracting information from a sentence using clausiepy |
e@1 | 9 |
e@1 | 10 """ |
e@1 | 11 |
e@1 | 12 from problog.extern import problog_export_nondet |
e@1 | 13 |
e@1 | 14 import clausiepy as cl |
e@1 | 15 |
e@1 | 16 def remove_apostrophe(string): |
e@1 | 17 # Remove "'"S |
e@1 | 18 if string[0] == "'": |
e@1 | 19 string = string[1:] |
e@1 | 20 if string[-1] == "'": |
e@1 | 21 string = string[:-1] |
e@1 | 22 |
e@1 | 23 return string |
e@1 | 24 |
e@1 | 25 @problog_export_nondet('+str', '-str', '-str', '-str', '-str', '-str', '-str') |
e@1 | 26 def clausie(sent): |
e@1 | 27 |
e@1 | 28 sent = remove_apostrophe(sent) |
e@1 | 29 |
e@1 | 30 clauses = cl.clausie(sent) |
e@1 | 31 |
e@1 | 32 propositions = cl.extract_propositions(clauses) |
e@1 | 33 |
e@1 | 34 result = [] |
e@1 | 35 for proposition in propositions: |
e@1 | 36 ptext = cl.proposition_text(proposition) |
e@1 | 37 |
e@1 | 38 prop = [] |
e@1 | 39 |
e@1 | 40 for p in ptext: |
e@1 | 41 prop.append(" ".join([pp.text for pp in p])) |
e@1 | 42 |
e@1 | 43 result.append(tuple(prop)) |
e@1 | 44 |
e@1 | 45 return result |