How to try it:
- Copy one of the examples into the "Datalog program" textbox
-
Click on the
Convert to bash script
button -
Copy the content of the "Bash script" textbox into a file named
query.sh
in the folder with the .tsv files (or click onDownload script
) -
Run it with
bash query.sh
tmp
for temporary files and removes its contents afterwards
API
You can also use bashlog from the command line, without a browser. For details, see API.Examples:
You can try the examples on this dataset (source). Unpack the dataset archive in a new folder (if unzip is installed:unzip sample.zip
).
- Find people that died in the city where they were born
facts(_, S, P, O) :~ cat *.tsv main(X) :- facts(_, X, "<wasBornIn>", Y), facts(_, X, "<diedIn>", Y).
- Living people
facts(_, S, P, O) :~ cat *.tsv born(X) :- facts(_, X, "<wasBornIn>", Y). born(X) :- facts(_, X, "<wasBornOnDate>", Y). dead(X) :- facts(_, X, "<diedIn>", Y). dead(X) :- facts(_, X, "<diedOnDate>", Y). main(X) :- born(X), not dead(X).
(you can find deceased people by removingnot
) - All people
facts(_, S, P, O) :~ cat *.tsv type(X, Y) :- facts(_, X, "rdf:type", Y). subclass(X, Y) :- facts(_, X, "rdfs:subclassOf", Y). type(X, Z) :- type(X, Y), subclass(Y, Z). main(X) :- type(X, "<wordnet_person_100007846>").
- Facts in a datalog program
type("albert", "person"). type("marie", "person"). people(X) :- type(X, "person").
Syntax:
Fact:head(Const1, Const2)).
Basic rule:
head(VarConst1, VarConst3) :- rel1(VarConst1, VarConst2), rel2(VarConst2, VarConst3).
with negation:
head(VarConst1, Var2) :- rel1(VarConst1, Var2), not rel2(Var2).
Bash rule, taking input from bash command:
head(Var1, Var2) :~ bash_command --options arg1 arg2 <newline>
Hints:
- the head of the last rule specifies the query
- variables must start with an upper case letter
- every head variable has to appear in the body
- predicates are lower case
- you can use Bash argument variables $1, $2, ..., in Bash rules.
Specify them when calling the script:
bash query.sh file1 file2