【发布时间】:2015-01-08 09:29:53
【问题描述】:
我想对句子执行一些操作,如字符串搜索、迭代、拆分等。我检查了几个 Prolog tuts 但没有帮助 - http://kti.ms.mff.cuni.cz/~bartak/prolog/contents.html,http://www.bitwisemag.com/copy/programming/prolog/intro/firststeps.html。我想写这样的程序:
for linking in post_script_link_list:
sub_link = re.search('\((.*?)\)',linking).group(1)
if sub_link in links_list1:
if ('Who').lower() in sent_split or 'Who' in sent_split:
result = 'person'
break
elif (('Where').lower() in sent_split or 'Where' in sent_split) and 'What' not in read_str and 'what' not in read_str:
result = 'location'
break
elif ('Why').lower() in sent_split or 'Why' in sent_split:
result = 'reason'
break
elif ('How many').lower() in read_str or 'How many' in read_str:
result = 'count'
break
elif (('When').lower() in sent_split or 'When' in sent_split) and 'What' not in read_str and 'what' not in read_str:
result = 'time'
break
elif (('How').lower() in sent_split or 'How' in sent_split) and ('How long').lower() not in read_str and 'How long' not in read_str and ('How much').lower() not in read_str and 'How much' not in read_str:
result = 'manner'
break
elif sub_link in links_list2:
check_yn = verify_yesno(post_script_link_list)
if check_yn == 1:
result = 'Yes/No'
break
elif check_yn == 0:
result = 'Not found'
break
break
else:
result = 'Not found'
是否可以执行 usnig prolog?我正在使用 pyswip 和 python
更新
1 ?- split_string("a.b.c.d", ".", "", L).
ERROR: toplevel: Undefined procedure: split_string/4 (DWIM could not correct goal)
【问题讨论】:
-
为什么要使用prolog?你所拥有的有什么问题?你有使用 prolog 或其他函数式编程语言的经验吗?
-
@VincentBeltman:是的,我对 prolog 的经验很少,其中有简单的规则,这很好。在基于规则的系统上工作时,使用 prolog 进行管理变得简单。在python的情况下,每次都需要编辑代码并添加if ... else,代码变得过于嵌套,复杂
-
我看到您的代码有很多改进。我可以稍微清理一下。或者您可以在代码审查中发布您的代码。
-
如果您使用 SWI-Prolog,还有“字符串”:swi-prolog.org/pldoc/man?section=strings“字符串”上的谓词在语义上比原子和代码列表更接近您想要实现的目标谓词。不过,这不会让您的工作变得更轻松,您似乎在组织思想方面存在问题。
-
@VincentBeltman:如果建议清理@codereview.stackexchange.com/questions/76956/…,我将不胜感激
标签: python prolog swi-prolog