Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 我怎样才能在prolog中读取一个文件,并在列表中列出几个单词?_File_List_Prolog - Fatal编程技术网

File 我怎样才能在prolog中读取一个文件,并在列表中列出几个单词?

File 我怎样才能在prolog中读取一个文件,并在列表中列出几个单词?,file,list,prolog,File,List,Prolog,我必须阅读results.txt,它包含一个由以下内容组成的树: 根( ( NP(…) 内华达州(……) . . ) ) 还有其他不适合我的东西 如何在列表中仅插入“根(…)” 谢谢尽管您的问题含糊不清,但这里有一段工作代码。您需要根据您的实际需求进行调整 tree(Tree) --> sym(Functor), "(", arguments(Args), ")", {Tree =.. [Functor|Args]}. sym(S) --> [F], { s

我必须阅读results.txt,它包含一个由以下内容组成的树:

根( ( NP(…) 内华达州(……) . . ) )

还有其他不适合我的东西

如何在列表中仅插入“根(…)”


谢谢

尽管您的问题含糊不清,但这里有一段工作代码。您需要根据您的实际需求进行调整

tree(Tree) -->
    sym(Functor), "(", arguments(Args), ")",
    {Tree =.. [Functor|Args]}.

sym(S) -->
    [F], { sym_char(F) },
    sym_rest(Cs),
    !, { atom_codes(S, [F|Cs]) }.

sym_rest([C|Cs]) -->
    [C], { sym_char(C) },
    sym_rest(Cs).
sym_rest([]) --> [].

sym_char(F) :- F >= 0'A, F =< 0'Z .

arguments([A|Args]) --> argument(A), ",", arguments(Args).
arguments([A]) --> argument(A).
argument(A) --> tree(A) ; sym(A).

... --> [] ; [_], ... .

尽管您的问题很模糊,但这里有一段工作代码。您需要根据您的实际需求进行调整

tree(Tree) -->
    sym(Functor), "(", arguments(Args), ")",
    {Tree =.. [Functor|Args]}.

sym(S) -->
    [F], { sym_char(F) },
    sym_rest(Cs),
    !, { atom_codes(S, [F|Cs]) }.

sym_rest([C|Cs]) -->
    [C], { sym_char(C) },
    sym_rest(Cs).
sym_rest([]) --> [].

sym_char(F) :- F >= 0'A, F =< 0'Z .

arguments([A|Args]) --> argument(A), ",", arguments(Args).
arguments([A]) --> argument(A).
argument(A) --> tree(A) ; sym(A).

... --> [] ; [_], ... .