序言中的文字处理 [英] word processing in prolog

查看:57
本文介绍了序言中的文字处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 prolog 中编写程序,使用谓词将单词分解为音节:第一个音节是元音-辅音-元音 .. 或第二个音节:元音-辅音-辅音-元音.例如;放弃 = 放弃 ..

How can I write a program in prolog that breaks a word into syllables using predicate: First syllable is vowel-consonant-vowel .. or Second syllable: vowel-consonant-consonant-vowel. For example; abandon = aba-ndon ..

推荐答案

这个程序基本上会应用你提到的规则,但我认为它不会成为文字处理的好工具.

This program will basically apply the rules you mention, but I don't think it will make a good tool for word processing.

vowel(a).
vowel(e).
vowel(i).
vowel(o).
vowel(u).
consonant(L):- not(vowel(L)).

syllable(W, S, RW):- atom_chars(W, [V1, C, V2|Tail]), vowel(V1), consonant(C), vowel(V2), !, atomic_list_concat([V1, C, V2], S), atomic_list_concat(Tail, RW).
syllable(W, S, RW):- atom_chars(W, [V1, C, C2, V2|Tail]), vowel(V1), consonant(C), consonant(C2),vowel(V2), !, atomic_list_concat([V1, C, C2, V2], S), atomic_list_concat(Tail, RW).
syllable(W, W, _).

break(W, B):- syllable(W, B, ''), !.
break(W, B):- syllable(W, S, RW), break(RW, B2), atomic_list_concat([S, '-', B2], B).

程序定义了元音是什么,不是什么.也是一个音节根据你的规则,以及如何打破一个词.使用谓词break/2"你可以测试它:

The program defines what a vowel is and what it is not. Also a syllable according to your rules, and how to break a word. Using the predicate ´break/2´ you can test it:

?- break(abaebbi, B).
B = 'aba-ebbi'

除了我糟糕的英语之外,让我怀疑你的规则是,用我的答案的每个单词进行测试,总是返回整个单词:)

What makes me doubt about your rules, besides my poor English, is that testing with each word of my answer, returns the entire word always :)

?-break('syllable', B).
B = syllable

这篇关于序言中的文字处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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