Mercurial > hg > chourdakisreiss2018dmrn
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:56c43da2d64c | 1:2082aeb1f1be |
---|---|
1 #!/usr/bin/env python3 | |
2 # -*- coding: utf-8 -*- | |
3 """ | |
4 Created on Wed Sep 26 13:38:38 2018 | |
5 | |
6 @author: Emmanouil Theofanis Chourdakis | |
7 | |
8 Problog module for extracting information from a sentence using clausiepy | |
9 | |
10 """ | |
11 | |
12 from problog.extern import problog_export_nondet | |
13 | |
14 import clausiepy as cl | |
15 | |
16 def remove_apostrophe(string): | |
17 # Remove "'"S | |
18 if string[0] == "'": | |
19 string = string[1:] | |
20 if string[-1] == "'": | |
21 string = string[:-1] | |
22 | |
23 return string | |
24 | |
25 @problog_export_nondet('+str', '-str', '-str', '-str', '-str', '-str', '-str') | |
26 def clausie(sent): | |
27 | |
28 sent = remove_apostrophe(sent) | |
29 | |
30 clauses = cl.clausie(sent) | |
31 | |
32 propositions = cl.extract_propositions(clauses) | |
33 | |
34 result = [] | |
35 for proposition in propositions: | |
36 ptext = cl.proposition_text(proposition) | |
37 | |
38 prop = [] | |
39 | |
40 for p in ptext: | |
41 prop.append(" ".join([pp.text for pp in p])) | |
42 | |
43 result.append(tuple(prop)) | |
44 | |
45 return result |