Check for words with Latin letters in the string

0

I need to check if there are words in the string with Latin letters.

For example, I enter a string in another language:

Enter the string: ыкеыу ролdfgdгп тми ваы 

The answer would be:

Words with latin letters: ролdfgdгп

This is my attempt but it is not correct, could someone help me please.

DOMAINS

        list_string = string*
        number_list = integer*
    I = integer
    C = char

 PREDICATES

    nondeterm result    
    nondeterm str_poisk(string,string)
    del_letter(char,string,string)
    str_pos(char,string,integer)
    str_delete(string,integer,integer,string)

 CLAUSES  

        str_poisk("",Result):-
        nl,
        write(" Words with latin letters: "),nl,
        write(Result),nl.
        str_poisk(Sin,Letter):-
        frontchar(Sin,C,S1),        
        del_letter(C,Letter,Result),    
        str_poisk(S1,Result).

    del_letter(C,StrIn,StrOut):-    
        str_pos(C,StrIn,Npos),
        Npos > 0, !, str_delete(StrIn,Npos,1,StrOut); str_delete(StrIn,1,0,StrOut).

        str_pos(C,S,1):-
        frontchar(S,C,_),!.

    str_pos(_,_,0). 

    str_delete(S,I,C,SO) :- 
        I1 = I - 1,
            frontstr(I1,S,S1,S2), 
            frontstr(C,S2,_,S3), 
            concat(S1,S3,SO).       

        result:-  
        nl, nl,
        write("   4. Check if there are words with latin letters in the string."), nl,
        write(" Enter the string: "),
        readln(Str),
        Letter = "abcdefghijklmnopqrstuvwxyz",
        str_poisk(Str,Letter),          
        readchar(_),!.

 GOAL
        result.
    
asked by Neon 25.05.2017 в 09:39
source

1 answer

0

You can break the string in words with the%% predicate of%, and by reevaluation check for each word, if it contains any valid characters:

words(S, W) :-
    split_string(S, " ", "", Ws),
    member(W, Ws),
    string_chars(W, Cs),
    latin(Cs).

latin([C|_]) :- char_code(C, N), N >= 97, N =< 122, !.
latin([_|Cs]) :- latin(Cs), !.

If you then need the solution in a list, you can get all the solutions with the split_string/4 predicate.

?- words("ыкеыу ролdfgdгп тми ваы", X).
X = "ролdfgdгп" ;
false.
    
answered by 27.05.2017 в 10:47