如何从序言中的rdf文件中删除条目

How to delete entry from rdf file in prolog

我想用 Prolog 编写一个程序,为用户提供一个菜单。他们选择添加数据,查看基于姓氏或年龄的现有数据,or/and 删除基于姓氏或年龄的数据。我不知道如何删除基于年龄或姓氏的条目。这是我写的。谁能告诉我我做错了什么?谢谢。

:- use_module(library(semweb/rdf_db)).
:- use_module(library(semweb/rdf_http_plugin)).
:- use_module(library(semweb/turtle)).

:- dynamic id/1.
id(1).

run :- nl,
   write('Option 1: Load new path'),nl,
   write('Option 2: Create new user'),nl,
   write('Option 3: Display data based on Surname'),nl,
   write('Option 4: Display data based on Age'),nl,
   write('Option 5: Delete data based on Surname'),nl,
   write('Option 6: Delete data based on Age'),nl,
   write('Option 7: Exit'),nl, %It saves the program before exiting
   write('Option(1-7): '), read(X), nl,
   ( shouldExit(X)
   ; (option(X), run)
   ; (nl, write('Invalid option.'), nl, run)
   ).

shouldExit(7) :- save.

option(1) :- write('Give path for rdf file'), read(Path), doOpen(Path).
option(2) :- doRead.
option(3) :- write('Surname: '), read(Surname), findS(Surname).
option(4) :- write('Age: '), read(Age), findA(Age). 
option(5) :- write('Surname: '), read(Surname), delS(Surname).
option(6) :- write('Age: '), read(Age), delA(Age).

/*Enter new user*/
doRead :- rdf_register_prefix(foaf,'http://xmlns.com/foaf/0.1/'),
          write('Surname:'), read(Surname),
          write('First Name:'), read(FirstName),
          write('Age:'), read(Age),
          id(N),
          New is N+1,
          retract(id(N)),
          asserta(id(New)),
          atom_concat('foaf:person', N, Person),
          rdf_assert(Person, rdf:type, foaf:'Person'),
          rdf_assert(Person, foaf:surname, literal(Surname)),
          rdf_assert(Person, foaf:firstName, literal(FirstName)),
          rdf_assert(Person, foaf:age, literal(Age)).
/*Display data based on Surname*/           
findS(Surname) :- rdf(X, foaf:surname, literal(Surname)),
                  rdf(X, foaf:firstName, literal(FirstName)),
                  rdf(X, foaf:age, literal(Age)),
                  write('Found '), write(FirstName), write(' '),
                  write(Surname), write(', '), write(Age), nl, fail.

/*Display data based on Age*/
findA(Age) :- rdf(X, foaf:surname, literal(Surname)),
              rdf(X, foaf:firstName, literal(FirstName)),
              rdf(X, foaf:age, literal(Age)),
              write('Found '), write(FirstName), write(' '),
              write(Surname), write(', '), write(Age), nl, fail.

/*Loads the file from the path the user asks ''*/
doOpen(Path) :- rdf_load(Path).

/*Saves the changes before exiting*/
save :- rdf_save(Path, [foaf]).

/*Deletes user based on their surname*/
/*delS(Surname) :- .*/

/*Deletes user based on their age*/
delA(Age) :- rdf(X, foaf:surname, literal(Surname)),
              rdf(X, foaf:firstName, literal(FirstName)),
              rdf(X, foaf:age, literal(Age)),
            retract(rdf(Surname, FirstName, Age)).

我不知道,所以这是一个猜测,但你正在使用:

retract(rdf(Surname, FirstName, Age)).

那是 Prolog retract/1, I think you need rdf_retractall