如何在 swi-prolog 中拆分一个句子 [英] how to split a sentence in swi-prolog

查看:41
本文介绍了如何在 swi-prolog 中拆分一个句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 win xp 中尝试使用 SWI-Prolog.我想了解如何将 Prolog 中的句子拆分为单独的原子.

I am trying my hands on SWI-Prolog in win xp. I am trying to understand how to split a sentence in Prolog into separate atoms.

例如:假设我有一个这样的句子:

Ex : Say I have a sentence like this :

这是一个字符串"
有没有办法让单个单词存储在变量中?

"this is a string"
Is there any way to get individual words to get stored in a variable?

喜欢:

X = 这个
Y = 是
....
等等.

X = this
Y = is
....
and so forth.

谁能解释一下这是如何工作的?

Can anyone please explain how this works?

谢谢.

推荐答案

我会使用 atomic_list_concat/3.见

I would use atomic_list_concat/3. See

http://www.swi-prolog.org/pldoc/man?predicate=atomic_list_concat%2F3

通常是为了插入一个分隔符,但由于 Prolog 的双向统一性,它也可以用于拆分字符串给定分隔符:

Normally it is meant to insert a separator but because of Prolog's bidirectionality of unification, it can also be used to split a string given the separator:

atomic_list_concat(L,' ', 'This is a string').
L = ['This',is,a,string]

当然,一旦拆分完成,您就可以使用列表 L 的元素.

Of course once the split is done you can play with the elements of the list L.

这篇关于如何在 swi-prolog 中拆分一个句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆