是否可以在序言中执行字符串处理

Is it possible to perform string processing in prolog

我想对句子执行一些操作,如字符串搜索、迭代、拆分等。我检查了几个 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)

要检查字符串是否包含特定子字符串,您可以使用 append/3sub_atom/5,具体取决于您表示字符串的方式。

如果您的字符串是原子,请使用 sub_atom/5:

substring(Atom, Substring):-
    sub_atom(Atom, _, _, _, Substring).

?- substring('... Where is that?', 'Where').
true ;
false.

如果您的字符串是代码列表,请使用 append/3:

substring(Codes, Substring):-
    append(S, _, Codes),
    append(_, Substring, S).

?- substring(".. Where is that?", "Where").
true ;
false.