我发现了一些关于相关问题的帖子,但没有帮助。我终于弄清楚了,以下是如何读取 .json 文件的内容。假设路径是/home/xxx/dnns/test/params.json,我想把.json中的字典变成Prolog字典:
{
"type": "lenet_1d",
"input_channel": 1,
"output_size": 130,
"batch_norm": 1,
"use_pooling": 1,
"pooling_method": "max",
"conv1_kernel_size": 17,
"conv1_num_kernels": 45,
"conv1_stride": 1,
"conv1_dropout": 0.0,
"pool1_kernel_size": 2,
"pool1_stride": 2,
"conv2_kernel_size": 12,
"conv2_num_kernels": 35,
"conv2_stride": 1,
"conv2_dropout": 0.514948804688646,
"pool2_kernel_size": 2,
"pool2_stride": 2,
"fcs_hidden_size": 109,
"fcs_num_hidden_layers": 2,
"fcs_dropout": 0.8559119274655482,
"cost_function": "SmoothL1",
"optimizer": "Adam",
"learning_rate": 0.0001802763794651928,
"momentum": null,
"data_is_target": 0,
"data_train": "/home/xxx/data/20180402_L74_70mm/train_2.h5",
"data_val": "/home/xxx/data/20180402_L74_70mm/val_2.h5",
"batch_size": 32,
"data_noise_gaussian": 1,
"weight_decay": 0,
"patience": 20,
"cuda": 1,
"save_initial": 0,
"k": 4,
"save_dir": "DNNs/20181203090415_11_created/k_4"
}
Run Code Online (Sandbox Code Playgroud) 我通过终端打开 SWI-Prolog,使用Swipl -s prolog_file. 然而,每次我向 Prolog 源文件添加新事实并保存时,我都必须在终端上重新启动 SWI-Prolog 以使其注意到更改。
我认为CTRL + s在 Prolog 源文件上使用足以让 SWI-Prolog 注意到更改,但事实并非如此。
在Windows上有一个带有编译按钮的Prolog编辑器,当你编译文件时,SWI-Prolog会注意到这些变化,但我使用的是Kali Linux,所以我在文本编辑器上编写。
如何让 SWI-Prolog 注意到这些变化?
swi-prolog 5.10.2
我已经输入了这个prolog程序.但是,当我运行选项a时,我得到以下错误.
go/0 Undefined Procedure save/1
Run Code Online (Sandbox Code Playgroud)
我确信save是一个正确的关键字谓词,并且该文件的路径也存在.不知道我在哪里错了.
What does the /0 /1 mean in go and save?
Run Code Online (Sandbox Code Playgroud)
源代码
/* Shopping list */
go:-reconsult('~/projects/prolog/chap7/shopping.pl'),
write('a: See list'), nl,
write('b: Add to list'), nl,
write('c: Delete from list'), nl,
read(Choice),
choice(Choice),
save('~/projects/prolog/chap7/shopping.pl').
/*
facts for shopping
*/
item(potatoes).
item(bread).
item(coffee).
/*
Rules for shopping list
*/
choice(a):-listing(item), nl.
choice(b):-write('Enter an item: '),
read(Item),
assert(item(Item)).
choice(c):-write('Item to delete: '),
read(Item),
retract(item(Item)).
choice(_):-write('Incorrect entry.'), nl.
Run Code Online (Sandbox Code Playgroud)
提前谢谢了,
我想知道从shell调用它时如何从SWI-Prolog输出.
说我有一个简单的知识库,kb.pl:
dad(elvis, lisaMarie).
dad(john, julian).
Run Code Online (Sandbox Code Playgroud)
我可以从shell调用SWI-Prolog:
$ swipl --quiet -s kb.pl -t listing
Run Code Online (Sandbox Code Playgroud)
并打印出我的知识库列表stdout.如果我试试这个:
$ swipl --quiet -s kb.pl -t "dad(elvis, X)"
$ echo $?
0
Run Code Online (Sandbox Code Playgroud)
没有输出打印,但我知道它找到了匹配,因为当我查询返回代码时我得到零.同理:
$ swipl --quiet -s kb.pl -t "dad(morrisey, X)"
$ echo $?
1
Run Code Online (Sandbox Code Playgroud)
显示Prolog正确无法找到匹配的事实.
我的问题是:如何打印所有匹配项,以便从shell中我可以看到输出,就像我在Prolog环境中一样?例如
$ swipl --quiet -s kb.pl -t "dad(elvis,X)" --magicdust
X = lisaMarie.
Run Code Online (Sandbox Code Playgroud)
我不认为--quiet是问题.它只是压制prolog启动消息.请参阅SWI-Prolog命令行选项
我面临的"问题"是,如果我使用SWI-Prolog模块系统,定义模块并在其他模块中使用它们,如果导入的模块发生变化,SWI-Prolog在加载导入模块时不会考虑它.例如:
% file topmod.pl
:- module(topmod, [thetop/0]).
:- use_module(bottommod).
thetop :-
thebottom(S),
format('This is the top~nAnd this is ~w~n', [S]).
% file bottommod.pl
:- module(bottommod, [thebottom/1]).
thebottom('the bottom').
Run Code Online (Sandbox Code Playgroud)
如果我现在加载它们:
?- [thetop].
% bottommod compiled into bottommod 0.00 sec, 2 clauses
% topmod compiled into topmod 0.00 sec, 6 clauses
true.
?- thetop.
This is the top
And this is the bottom
true.
Run Code Online (Sandbox Code Playgroud)
如果我现在更改文件:
% file bottommod.pl changes
- thebottom('the bottom').
+ thebottom('the foobar').
?- [thetop].
% …Run Code Online (Sandbox Code Playgroud) 我知道这是一个有点愚蠢的问题,但我现在真的很绝望,因为我无法找到建立它的方法.我总是得到这个错误
ERROR: call/2: Undefined procedure: main/1
ERROR: However, there are definitions for:
ERROR: main/0
Run Code Online (Sandbox Code Playgroud)
即使我试过了
father(ahmad,samer).
father(ahmad,lolo).
father(ahmad,koko).
grandfather(X,Y):-
father(U,X),
father(Y,U).
main :- father(ahmad, X), writef('%t\n', [X]).
Run Code Online (Sandbox Code Playgroud)
那么有人可以帮助我以正确的方式做到这一点吗?
我想最大化两个变量之间的差异:
:- use_module(library(clpfd)).
maximize(X) :-
X = [A,B],
X ins 1..5,
% I want to write a constraint to have maximum difference between A and B.
Run Code Online (Sandbox Code Playgroud) 我正在尝试测试安装包如何与SWI-prolog一起工作,但得到了这个:
?- pack_install('https://github.com/propack/app/archive/app-0.0.1.zip').
% library(ssl) compiled into ssl 0.00 sec, 43 clauses
% library(rbtrees) compiled into rbtrees 0.01 sec, 190 clauses
% library(thread_pool) compiled into thread_pool 0.01 sec, 238 clauses
% http_wrapper compiled into httpd_wrapper 0.00 sec, 68 clauses
% thread_httpd compiled into thread_httpd 0.02 sec, 407 clauses
% library(http/http_ssl_plugin) compiled into http_ssl_plugin 0.03 sec, 462 clauses
Create directory for packages
(1) * /Users/lancejpollard/lib/swipl/pack
(2) /usr/local/Cellar/swi-prolog/6.6.6/libexec/lib/swipl-6.6.6/pack
(3) Cancel
Your choice? 1
ERROR: library `archive' does not exist
Exception: (10) prolog_pack:pack_archive_info('/Users/lancejpollard/lib/swipl/pack/Downloads/app-0.0.1.zip', …Run Code Online (Sandbox Code Playgroud) 因此,我有一些Prolog代码可以对变量分配进行建模,例如以一种编程语言进行建模,并尝试查看它们是否相互兼容。所以,
assigned(X, X).
and(P, Q) :- P, Q.
or(P, Q) :- P.
or(P, Q) :- Q.
% and then we should test an expression like this:
and(assigned(X, 5), assigned(X, 6)).
Run Code Online (Sandbox Code Playgroud)
由于X不能同时分配给5和6 ,因此最后一个表达式失败。
现在,我想做的就是让这个测试具有单个表达式(可以并且应该将其硬编码到文件中),然后简单地打印出是否能够满足要求。但是似乎SWIPL 确实希望我能够交互式运行。理想情况是这样的:
> ./test-assignments
false.
Run Code Online (Sandbox Code Playgroud)
当然可以吗?我在这方面机智。
swi-prolog ×10
prolog ×8
clpfd ×1
json ×1
logtalk ×1
module ×1
package ×1
shell ×1
sublimetext3 ×1
terminal ×1
text-editor ×1
xpce ×1