简单的字符串拆分SWI-Prolog不工作

时间:2015-07-15 15:27:29

标签: string prolog

我在SWI-prolog中创建了一个用于形态解析的数据库,但我遇到了一个问题。我现在把它煮到了问题区域。

lexicon('a', 'foo').
inflection('bc', 'bar').

morph(Input, Output) :-
    string_concat(First, Second, Input),
    intepretation(First, Second, Output).   

intepretation(First, Second, Output) :-
    lexicon(First, Foo),
    inflection(Second, Bar),
    string_concat(Foo, Bar, Output).

基本上,我给出命令“morph('abc',X)”并且我期望输出“X ='foobar'”但是我得到“假”。数据库简单地将输入字符串拆分为两个字符串,并尝试查找描述生成的子字符串的规则。如果找不到,它会再次将输入字符串拆分到另一个位置并再次尝试。显然,它应该发现,如果它将'abc'分成'a'和'bc',则存在适当的规则,但事实并非如此。

这是一个跟踪:

   Call: (6) morph(abc, _G1441) ? creep
   Call: (7) string_concat(_G1513, _G1514, abc) ? creep
   Exit: (7) string_concat("", "abc", abc) ? creep
   Call: (7) intepretation("", "abc", _G1441) ? creep
   Call: (8) lexicon("", _G1520) ? creep
   Fail: (8) lexicon("", _G1520) ? creep
   Fail: (7) intepretation("", "abc", _G1441) ? creep
   Redo: (7) string_concat(_G1513, _G1514, abc) ? creep
   Exit: (7) string_concat("a", "bc", abc) ? creep
   Call: (7) intepretation("a", "bc", _G1441) ? creep
   Call: (8) lexicon("a", _G1520) ? creep
   Fail: (8) lexicon("a", _G1520) ? creep                    % What's happening on this line?
   Fail: (7) intepretation("a", "bc", _G1441) ? creep
   Redo: (7) string_concat(_G1513, _G1514, abc) ? creep
   Exit: (7) string_concat("ab", "c", abc) ? creep
   Call: (7) intepretation("ab", "c", _G1441) ? creep
   Call: (8) lexicon("ab", _G1520) ? creep
   Fail: (8) lexicon("ab", _G1520) ? creep
   Fail: (7) intepretation("ab", "c", _G1441) ? creep
   Redo: (7) string_concat(_G1513, _G1514, abc) ? creep
   Exit: (7) string_concat("abc", "", abc) ? creep
   Call: (7) intepretation("abc", "", _G1441) ? creep
   Call: (8) lexicon("abc", _G1520) ? creep
   Fail: (8) lexicon("abc", _G1520) ? creep
   Fail: (7) intepretation("abc", "", _G1441) ? creep
   Fail: (6) morph(abc, _G1441) ? creep

我确信这是我误解字符串或其他东西的结果。我很感激任何帮助,谢谢。

0 个答案:

没有答案
相关问题