kibi-swipl-linux-x64-gnu 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (550) hide show
  1. package/README.md +29 -0
  2. package/bin/swipl +0 -0
  3. package/bin/swipl-win +0 -0
  4. package/build-manifest.json +70 -0
  5. package/lib/cmake/swipl/SWIPLConfig.cmake +21 -0
  6. package/lib/cmake/swipl/SWIPLConfigVersion.cmake +65 -0
  7. package/lib/cmake/swipl/SWIPLTargets-release.cmake +28 -0
  8. package/lib/cmake/swipl/SWIPLTargets.cmake +109 -0
  9. package/lib/swipl/ABI +1 -0
  10. package/lib/swipl/LICENSE +41 -0
  11. package/lib/swipl/README.md +116 -0
  12. package/lib/swipl/app/README.md +25 -0
  13. package/lib/swipl/app/app.pl +87 -0
  14. package/lib/swipl/app/pack.pl +350 -0
  15. package/lib/swipl/app/qlf.pl +521 -0
  16. package/lib/swipl/app/splfr.pl +177 -0
  17. package/lib/swipl/app/sys.pl +310 -0
  18. package/lib/swipl/bin/swipl.home +1 -0
  19. package/lib/swipl/boot/apply.pl +73 -0
  20. package/lib/swipl/boot/attvar.pl +344 -0
  21. package/lib/swipl/boot/autoload.pl +1226 -0
  22. package/lib/swipl/boot/bags.pl +283 -0
  23. package/lib/swipl/boot/dcg.pl +388 -0
  24. package/lib/swipl/boot/dicts.pl +193 -0
  25. package/lib/swipl/boot/dwim.pl +485 -0
  26. package/lib/swipl/boot/engines.pl +152 -0
  27. package/lib/swipl/boot/expand.pl +1628 -0
  28. package/lib/swipl/boot/gc.pl +65 -0
  29. package/lib/swipl/boot/history.pl +304 -0
  30. package/lib/swipl/boot/init.pl +4682 -0
  31. package/lib/swipl/boot/iri.pl +64 -0
  32. package/lib/swipl/boot/license.pl +390 -0
  33. package/lib/swipl/boot/load.pl +81 -0
  34. package/lib/swipl/boot/messages.pl +2521 -0
  35. package/lib/swipl/boot/packs.pl +306 -0
  36. package/lib/swipl/boot/predopts.pl +154 -0
  37. package/lib/swipl/boot/qlf.pl +141 -0
  38. package/lib/swipl/boot/rc.pl +263 -0
  39. package/lib/swipl/boot/syspred.pl +1634 -0
  40. package/lib/swipl/boot/tabling.pl +2321 -0
  41. package/lib/swipl/boot/threads.pl +42 -0
  42. package/lib/swipl/boot/toplevel.pl +2248 -0
  43. package/lib/swipl/boot/topvars.pl +261 -0
  44. package/lib/swipl/boot.prc +0 -0
  45. package/lib/swipl/cmake/swipl.cmake +131 -0
  46. package/lib/swipl/customize/README.md +23 -0
  47. package/lib/swipl/customize/edit +101 -0
  48. package/lib/swipl/customize/init.pl +164 -0
  49. package/lib/swipl/demo/README.md +33 -0
  50. package/lib/swipl/demo/likes.pl +44 -0
  51. package/lib/swipl/doc/packages/examples/chr/bool.chr +281 -0
  52. package/lib/swipl/doc/packages/examples/chr/chrdif.chr +87 -0
  53. package/lib/swipl/doc/packages/examples/chr/chrfreeze.chr +6 -0
  54. package/lib/swipl/doc/packages/examples/chr/family.chr +116 -0
  55. package/lib/swipl/doc/packages/examples/chr/fib.chr +24 -0
  56. package/lib/swipl/doc/packages/examples/chr/fibonacci.chr +31 -0
  57. package/lib/swipl/doc/packages/examples/chr/gcd.chr +28 -0
  58. package/lib/swipl/doc/packages/examples/chr/leq.chr +34 -0
  59. package/lib/swipl/doc/packages/examples/chr/listdom.chr +138 -0
  60. package/lib/swipl/doc/packages/examples/chr/primes.chr +29 -0
  61. package/lib/swipl/doc/packages/examples/http/README.md +98 -0
  62. package/lib/swipl/doc/packages/examples/http/calc.pl +92 -0
  63. package/lib/swipl/doc/packages/examples/http/demo_body.pl +232 -0
  64. package/lib/swipl/doc/packages/examples/http/demo_client.pl +165 -0
  65. package/lib/swipl/doc/packages/examples/http/demo_daemon.pl +38 -0
  66. package/lib/swipl/doc/packages/examples/http/demo_files.pl +50 -0
  67. package/lib/swipl/doc/packages/examples/http/demo_hello.pl +15 -0
  68. package/lib/swipl/doc/packages/examples/http/demo_login.pl +280 -0
  69. package/lib/swipl/doc/packages/examples/http/demo_openid.pl +177 -0
  70. package/lib/swipl/doc/packages/examples/http/demo_pwp.pl +20 -0
  71. package/lib/swipl/doc/packages/examples/http/demo_rest.pl +56 -0
  72. package/lib/swipl/doc/packages/examples/http/demo_threads.pl +52 -0
  73. package/lib/swipl/doc/packages/examples/http/linux-init-script +126 -0
  74. package/lib/swipl/doc/packages/examples/http/pwp/context.pwp +23 -0
  75. package/lib/swipl/doc/packages/examples/http/pwp/index.pwp +25 -0
  76. package/lib/swipl/doc/packages/examples/http/pwp/pwp1.pwp +12 -0
  77. package/lib/swipl/doc/packages/examples/http/pwp/pwp2.pwp +10 -0
  78. package/lib/swipl/doc/packages/examples/http/pwp/pwp3.pwp +25 -0
  79. package/lib/swipl/doc/packages/examples/http/pwp/pwp4.pwp +23 -0
  80. package/lib/swipl/doc/packages/examples/http/pwp/pwp5.pwp +11 -0
  81. package/lib/swipl/doc/packages/examples/http/pwp/pwp6.pwp +3 -0
  82. package/lib/swipl/doc/packages/examples/http/pwp/pwp7.pwp +3 -0
  83. package/lib/swipl/doc/packages/examples/http/pwp/pwp8.pwp +3 -0
  84. package/lib/swipl/doc/packages/examples/http/pwp/pwpdb.pl +12 -0
  85. package/lib/swipl/doc/packages/examples/http/systemd-script.service +18 -0
  86. package/lib/swipl/doc/packages/examples/http/upstart-script.conf +20 -0
  87. package/lib/swipl/doc/packages/examples/plunit/read.pl +17 -0
  88. package/lib/swipl/doc/packages/examples/plunit/simple.pl +33 -0
  89. package/lib/swipl/doc/packages/examples/ssl/client.pl +83 -0
  90. package/lib/swipl/doc/packages/examples/ssl/etc/README +52 -0
  91. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.p12 +0 -0
  92. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.pem +85 -0
  93. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-key.pem +30 -0
  94. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/cacert.pem +82 -0
  95. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/careq.pem +18 -0
  96. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/crlnumber +1 -0
  97. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt +3 -0
  98. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt.attr +1 -0
  99. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7C.pem +85 -0
  100. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7D.pem +85 -0
  101. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/private/cakey.pem +30 -0
  102. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/serial +1 -0
  103. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-cert.pem +85 -0
  104. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-key.pem +30 -0
  105. package/lib/swipl/doc/packages/examples/ssl/https.pl +267 -0
  106. package/lib/swipl/doc/packages/examples/ssl/server.pl +106 -0
  107. package/lib/swipl/include/SWI-Prolog.h +1544 -0
  108. package/lib/swipl/include/SWI-Stream.h +537 -0
  109. package/lib/swipl/include/Yap/YapInterface.h +283 -0
  110. package/lib/swipl/include/sicstus/sicstus.h +452 -0
  111. package/lib/swipl/lib/x86_64-linux/cgi.so +0 -0
  112. package/lib/swipl/lib/x86_64-linux/crypt.so +0 -0
  113. package/lib/swipl/lib/x86_64-linux/crypto4pl.so +0 -0
  114. package/lib/swipl/lib/x86_64-linux/double_metaphone.so +0 -0
  115. package/lib/swipl/lib/x86_64-linux/files.so +0 -0
  116. package/lib/swipl/lib/x86_64-linux/hashstream.so +0 -0
  117. package/lib/swipl/lib/x86_64-linux/http_stream.so +0 -0
  118. package/lib/swipl/lib/x86_64-linux/isub.so +0 -0
  119. package/lib/swipl/lib/x86_64-linux/json.so +0 -0
  120. package/lib/swipl/lib/x86_64-linux/libswipl.so.10 +0 -0
  121. package/lib/swipl/lib/x86_64-linux/mallocinfo.so +0 -0
  122. package/lib/swipl/lib/x86_64-linux/md54pl.so +0 -0
  123. package/lib/swipl/lib/x86_64-linux/memfile.so +0 -0
  124. package/lib/swipl/lib/x86_64-linux/ntriples.so +0 -0
  125. package/lib/swipl/lib/x86_64-linux/pcre4pl.so +0 -0
  126. package/lib/swipl/lib/x86_64-linux/porter_stem.so +0 -0
  127. package/lib/swipl/lib/x86_64-linux/process.so +0 -0
  128. package/lib/swipl/lib/x86_64-linux/prolog_stream.so +0 -0
  129. package/lib/swipl/lib/x86_64-linux/rdf_db.so +0 -0
  130. package/lib/swipl/lib/x86_64-linux/readutil.so +0 -0
  131. package/lib/swipl/lib/x86_64-linux/rlimit.so +0 -0
  132. package/lib/swipl/lib/x86_64-linux/sched.so +0 -0
  133. package/lib/swipl/lib/x86_64-linux/sgml2pl.so +0 -0
  134. package/lib/swipl/lib/x86_64-linux/sha4pl.so +0 -0
  135. package/lib/swipl/lib/x86_64-linux/snowball.so +0 -0
  136. package/lib/swipl/lib/x86_64-linux/socket.so +0 -0
  137. package/lib/swipl/lib/x86_64-linux/ssl4pl.so +0 -0
  138. package/lib/swipl/lib/x86_64-linux/streaminfo.so +0 -0
  139. package/lib/swipl/lib/x86_64-linux/syslog.so +0 -0
  140. package/lib/swipl/lib/x86_64-linux/time.so +0 -0
  141. package/lib/swipl/lib/x86_64-linux/turtle.so +0 -0
  142. package/lib/swipl/lib/x86_64-linux/uid.so +0 -0
  143. package/lib/swipl/lib/x86_64-linux/unix.so +0 -0
  144. package/lib/swipl/lib/x86_64-linux/uri.so +0 -0
  145. package/lib/swipl/lib/x86_64-linux/websocket.so +0 -0
  146. package/lib/swipl/lib/x86_64-linux/zlib4pl.so +0 -0
  147. package/lib/swipl/library/INDEX.pl +1020 -0
  148. package/lib/swipl/library/aggregate.pl +755 -0
  149. package/lib/swipl/library/ansi_term.pl +653 -0
  150. package/lib/swipl/library/apply.pl +426 -0
  151. package/lib/swipl/library/apply_macros.pl +497 -0
  152. package/lib/swipl/library/arithmetic.pl +320 -0
  153. package/lib/swipl/library/assoc.pl +522 -0
  154. package/lib/swipl/library/atom.pl +169 -0
  155. package/lib/swipl/library/backcomp.pl +688 -0
  156. package/lib/swipl/library/base32.pl +291 -0
  157. package/lib/swipl/library/base64.pl +441 -0
  158. package/lib/swipl/library/broadcast.pl +161 -0
  159. package/lib/swipl/library/build/cmake.pl +137 -0
  160. package/lib/swipl/library/build/conan.pl +232 -0
  161. package/lib/swipl/library/build/make.pl +168 -0
  162. package/lib/swipl/library/build/tools.pl +825 -0
  163. package/lib/swipl/library/charsio.pl +195 -0
  164. package/lib/swipl/library/check.pl +1097 -0
  165. package/lib/swipl/library/check_installation.pl +912 -0
  166. package/lib/swipl/library/clp/INDEX.pl +157 -0
  167. package/lib/swipl/library/clp/bounds.pl +2036 -0
  168. package/lib/swipl/library/clp/clp_distinct.pl +263 -0
  169. package/lib/swipl/library/clp/clp_events.pl +92 -0
  170. package/lib/swipl/library/clp/clpb.pl +1896 -0
  171. package/lib/swipl/library/clp/clpfd.pl +7906 -0
  172. package/lib/swipl/library/clp/simplex.pl +1580 -0
  173. package/lib/swipl/library/codesio.pl +182 -0
  174. package/lib/swipl/library/coinduction.pl +183 -0
  175. package/lib/swipl/library/console_input.pl +289 -0
  176. package/lib/swipl/library/csv.pl +611 -0
  177. package/lib/swipl/library/ctypes.pl +161 -0
  178. package/lib/swipl/library/date.pl +370 -0
  179. package/lib/swipl/library/dcg/INDEX.pl +35 -0
  180. package/lib/swipl/library/dcg/basics.pl +514 -0
  181. package/lib/swipl/library/dcg/high_order.pl +227 -0
  182. package/lib/swipl/library/debug.pl +499 -0
  183. package/lib/swipl/library/dialect/bim.pl +186 -0
  184. package/lib/swipl/library/dialect/commons.pl +77 -0
  185. package/lib/swipl/library/dialect/eclipse/test_util_iso.pl +355 -0
  186. package/lib/swipl/library/dialect/hprolog/format.pl +44 -0
  187. package/lib/swipl/library/dialect/hprolog.pl +314 -0
  188. package/lib/swipl/library/dialect/ifprolog.pl +1317 -0
  189. package/lib/swipl/library/dialect/iso/iso_predicates.pl +277 -0
  190. package/lib/swipl/library/dialect/sicstus/README.TXT +1 -0
  191. package/lib/swipl/library/dialect/sicstus/arrays.pl +121 -0
  192. package/lib/swipl/library/dialect/sicstus/block.pl +278 -0
  193. package/lib/swipl/library/dialect/sicstus/lists.pl +167 -0
  194. package/lib/swipl/library/dialect/sicstus/ordsets.pl +52 -0
  195. package/lib/swipl/library/dialect/sicstus/sockets.pl +174 -0
  196. package/lib/swipl/library/dialect/sicstus/system.pl +262 -0
  197. package/lib/swipl/library/dialect/sicstus/terms.pl +57 -0
  198. package/lib/swipl/library/dialect/sicstus/timeout.pl +92 -0
  199. package/lib/swipl/library/dialect/sicstus.pl +582 -0
  200. package/lib/swipl/library/dialect/sicstus4/aggregate.pl +60 -0
  201. package/lib/swipl/library/dialect/sicstus4/between.pl +62 -0
  202. package/lib/swipl/library/dialect/sicstus4/clpfd.pl +75 -0
  203. package/lib/swipl/library/dialect/sicstus4/file_systems.pl +413 -0
  204. package/lib/swipl/library/dialect/sicstus4/lists.pl +274 -0
  205. package/lib/swipl/library/dialect/sicstus4/ordsets.pl +54 -0
  206. package/lib/swipl/library/dialect/sicstus4/samsort.pl +86 -0
  207. package/lib/swipl/library/dialect/sicstus4/sets.pl +124 -0
  208. package/lib/swipl/library/dialect/sicstus4/sockets.pl +164 -0
  209. package/lib/swipl/library/dialect/sicstus4/system.pl +80 -0
  210. package/lib/swipl/library/dialect/sicstus4/terms.pl +89 -0
  211. package/lib/swipl/library/dialect/sicstus4/timeout.pl +43 -0
  212. package/lib/swipl/library/dialect/sicstus4/types.pl +103 -0
  213. package/lib/swipl/library/dialect/sicstus4.pl +200 -0
  214. package/lib/swipl/library/dialect/swi/syspred_options.pl +250 -0
  215. package/lib/swipl/library/dialect/xsb/README.md +20 -0
  216. package/lib/swipl/library/dialect/xsb/basics.pl +318 -0
  217. package/lib/swipl/library/dialect/xsb/consult.pl +87 -0
  218. package/lib/swipl/library/dialect/xsb/curr_sym.pl +57 -0
  219. package/lib/swipl/library/dialect/xsb/error_handler.pl +111 -0
  220. package/lib/swipl/library/dialect/xsb/gensym.pl +53 -0
  221. package/lib/swipl/library/dialect/xsb/gpp.pl +138 -0
  222. package/lib/swipl/library/dialect/xsb/intern.pl +48 -0
  223. package/lib/swipl/library/dialect/xsb/lists.pl +47 -0
  224. package/lib/swipl/library/dialect/xsb/machine.pl +295 -0
  225. package/lib/swipl/library/dialect/xsb/ordsets.pl +53 -0
  226. package/lib/swipl/library/dialect/xsb/setof.pl +54 -0
  227. package/lib/swipl/library/dialect/xsb/source.pl +308 -0
  228. package/lib/swipl/library/dialect/xsb/standard.pl +169 -0
  229. package/lib/swipl/library/dialect/xsb/storage.pl +70 -0
  230. package/lib/swipl/library/dialect/xsb/string.pl +76 -0
  231. package/lib/swipl/library/dialect/xsb/thread.pl +62 -0
  232. package/lib/swipl/library/dialect/xsb/timed_call.pl +158 -0
  233. package/lib/swipl/library/dialect/xsb.pl +688 -0
  234. package/lib/swipl/library/dialect/yap/README.TXT +8 -0
  235. package/lib/swipl/library/dialect/yap.pl +283 -0
  236. package/lib/swipl/library/dialect.pl +123 -0
  237. package/lib/swipl/library/dicts.pl +399 -0
  238. package/lib/swipl/library/dif.pl +426 -0
  239. package/lib/swipl/library/edinburgh.pl +138 -0
  240. package/lib/swipl/library/edit.pl +783 -0
  241. package/lib/swipl/library/error.pl +495 -0
  242. package/lib/swipl/library/exceptions.pl +231 -0
  243. package/lib/swipl/library/explain.pl +543 -0
  244. package/lib/swipl/library/ext/RDF/INDEX.pl +25 -0
  245. package/lib/swipl/library/ext/RDF/rdf.pl +450 -0
  246. package/lib/swipl/library/ext/RDF/rdf_parser.pl +649 -0
  247. package/lib/swipl/library/ext/RDF/rdf_triple.pl +448 -0
  248. package/lib/swipl/library/ext/RDF/rdf_write.pl +701 -0
  249. package/lib/swipl/library/ext/RDF/rewrite_term.pl +177 -0
  250. package/lib/swipl/library/ext/chr/chr/a_star.pl +80 -0
  251. package/lib/swipl/library/ext/chr/chr/binomialheap.pl +142 -0
  252. package/lib/swipl/library/ext/chr/chr/builtins.pl +629 -0
  253. package/lib/swipl/library/ext/chr/chr/chr_compiler_errors.pl +179 -0
  254. package/lib/swipl/library/ext/chr/chr/chr_compiler_options.pl +382 -0
  255. package/lib/swipl/library/ext/chr/chr/chr_compiler_utility.pl +338 -0
  256. package/lib/swipl/library/ext/chr/chr/chr_debug.pl +59 -0
  257. package/lib/swipl/library/ext/chr/chr/chr_hashtable_store.pl +425 -0
  258. package/lib/swipl/library/ext/chr/chr/chr_integertable_store.pl +139 -0
  259. package/lib/swipl/library/ext/chr/chr/chr_messages.pl +176 -0
  260. package/lib/swipl/library/ext/chr/chr/chr_op.pl +53 -0
  261. package/lib/swipl/library/ext/chr/chr/chr_runtime.pl +1016 -0
  262. package/lib/swipl/library/ext/chr/chr/chr_translate.pl +25424 -0
  263. package/lib/swipl/library/ext/chr/chr/clean_code.pl +252 -0
  264. package/lib/swipl/library/ext/chr/chr/find.pl +78 -0
  265. package/lib/swipl/library/ext/chr/chr/guard_entailment.pl +19432 -0
  266. package/lib/swipl/library/ext/chr/chr/listmap.pl +108 -0
  267. package/lib/swipl/library/ext/chr/chr/pairlist.pl +78 -0
  268. package/lib/swipl/library/ext/chr/chr.pl +686 -0
  269. package/lib/swipl/library/ext/clib/INDEX.pl +158 -0
  270. package/lib/swipl/library/ext/clib/cgi.pl +86 -0
  271. package/lib/swipl/library/ext/clib/crypt.pl +44 -0
  272. package/lib/swipl/library/ext/clib/filesex.pl +644 -0
  273. package/lib/swipl/library/ext/clib/hash_stream.pl +119 -0
  274. package/lib/swipl/library/ext/clib/mallocinfo.pl +138 -0
  275. package/lib/swipl/library/ext/clib/md5.pl +68 -0
  276. package/lib/swipl/library/ext/clib/memfile.pl +61 -0
  277. package/lib/swipl/library/ext/clib/process.pl +573 -0
  278. package/lib/swipl/library/ext/clib/prolog_server.pl +157 -0
  279. package/lib/swipl/library/ext/clib/prolog_stream.pl +80 -0
  280. package/lib/swipl/library/ext/clib/rlimit.pl +54 -0
  281. package/lib/swipl/library/ext/clib/sched.pl +85 -0
  282. package/lib/swipl/library/ext/clib/sha.pl +162 -0
  283. package/lib/swipl/library/ext/clib/socket.pl +1102 -0
  284. package/lib/swipl/library/ext/clib/streaminfo.pl +103 -0
  285. package/lib/swipl/library/ext/clib/streampool.pl +136 -0
  286. package/lib/swipl/library/ext/clib/syslog.pl +180 -0
  287. package/lib/swipl/library/ext/clib/time.pl +194 -0
  288. package/lib/swipl/library/ext/clib/udp_broadcast.pl +975 -0
  289. package/lib/swipl/library/ext/clib/uid.pl +220 -0
  290. package/lib/swipl/library/ext/clib/unix.pl +317 -0
  291. package/lib/swipl/library/ext/clib/uri.pl +530 -0
  292. package/lib/swipl/library/ext/clib/uuid.pl +207 -0
  293. package/lib/swipl/library/ext/http/http/INDEX.pl +266 -0
  294. package/lib/swipl/library/ext/http/http/README.md +34 -0
  295. package/lib/swipl/library/ext/http/http/ax.pl +189 -0
  296. package/lib/swipl/library/ext/http/http/dcg_basics.pl +49 -0
  297. package/lib/swipl/library/ext/http/http/graphql.pl +1367 -0
  298. package/lib/swipl/library/ext/http/http/html_decl.pl +416 -0
  299. package/lib/swipl/library/ext/http/http/html_head.pl +654 -0
  300. package/lib/swipl/library/ext/http/http/html_quasiquotations.pl +120 -0
  301. package/lib/swipl/library/ext/http/http/html_write.pl +1425 -0
  302. package/lib/swipl/library/ext/http/http/htmx.pl +139 -0
  303. package/lib/swipl/library/ext/http/http/http_authenticate.pl +364 -0
  304. package/lib/swipl/library/ext/http/http/http_client.pl +412 -0
  305. package/lib/swipl/library/ext/http/http/http_cookie.pl +245 -0
  306. package/lib/swipl/library/ext/http/http/http_cors.pl +176 -0
  307. package/lib/swipl/library/ext/http/http/http_digest.pl +820 -0
  308. package/lib/swipl/library/ext/http/http/http_dirindex.pl +296 -0
  309. package/lib/swipl/library/ext/http/http/http_dispatch.pl +1552 -0
  310. package/lib/swipl/library/ext/http/http/http_dyn_workers.pl +214 -0
  311. package/lib/swipl/library/ext/http/http/http_error.pl +126 -0
  312. package/lib/swipl/library/ext/http/http/http_exception.pl +225 -0
  313. package/lib/swipl/library/ext/http/http/http_files.pl +163 -0
  314. package/lib/swipl/library/ext/http/http/http_header.pl +2820 -0
  315. package/lib/swipl/library/ext/http/http/http_hook.pl +106 -0
  316. package/lib/swipl/library/ext/http/http/http_host.pl +204 -0
  317. package/lib/swipl/library/ext/http/http/http_load.pl +113 -0
  318. package/lib/swipl/library/ext/http/http/http_log.pl +738 -0
  319. package/lib/swipl/library/ext/http/http/http_multipart_plugin.pl +232 -0
  320. package/lib/swipl/library/ext/http/http/http_open.pl +1821 -0
  321. package/lib/swipl/library/ext/http/http/http_openid.pl +1561 -0
  322. package/lib/swipl/library/ext/http/http/http_parameters.pl +504 -0
  323. package/lib/swipl/library/ext/http/http/http_path.pl +380 -0
  324. package/lib/swipl/library/ext/http/http/http_proxy.pl +80 -0
  325. package/lib/swipl/library/ext/http/http/http_pwp.pl +351 -0
  326. package/lib/swipl/library/ext/http/http/http_redis_plugin.pl +332 -0
  327. package/lib/swipl/library/ext/http/http/http_server.pl +105 -0
  328. package/lib/swipl/library/ext/http/http/http_server_files.pl +126 -0
  329. package/lib/swipl/library/ext/http/http/http_server_health.pl +186 -0
  330. package/lib/swipl/library/ext/http/http/http_session.pl +1040 -0
  331. package/lib/swipl/library/ext/http/http/http_sgml_plugin.pl +137 -0
  332. package/lib/swipl/library/ext/http/http/http_stream.pl +376 -0
  333. package/lib/swipl/library/ext/http/http/http_unix_daemon.pl +989 -0
  334. package/lib/swipl/library/ext/http/http/http_wrapper.pl +559 -0
  335. package/lib/swipl/library/ext/http/http/hub.pl +600 -0
  336. package/lib/swipl/library/ext/http/http/js_write.pl +461 -0
  337. package/lib/swipl/library/ext/http/http/mimepack.pl +224 -0
  338. package/lib/swipl/library/ext/http/http/mimetype.pl +276 -0
  339. package/lib/swipl/library/ext/http/http/term_html.pl +797 -0
  340. package/lib/swipl/library/ext/http/http/thread_httpd.pl +1181 -0
  341. package/lib/swipl/library/ext/http/http/web/css/dirindex.css +24 -0
  342. package/lib/swipl/library/ext/http/http/web/css/openid.css +57 -0
  343. package/lib/swipl/library/ext/http/http/web/icons/back.png +0 -0
  344. package/lib/swipl/library/ext/http/http/web/icons/c.png +0 -0
  345. package/lib/swipl/library/ext/http/http/web/icons/compressed.png +0 -0
  346. package/lib/swipl/library/ext/http/http/web/icons/folder.png +0 -0
  347. package/lib/swipl/library/ext/http/http/web/icons/generic.png +0 -0
  348. package/lib/swipl/library/ext/http/http/web/icons/layout.png +0 -0
  349. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-square.png +0 -0
  350. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-tiny.png +0 -0
  351. package/lib/swipl/library/ext/http/http/websocket.pl +729 -0
  352. package/lib/swipl/library/ext/http/http/yadis.pl +205 -0
  353. package/lib/swipl/library/ext/json/INDEX.pl +36 -0
  354. package/lib/swipl/library/ext/json/http/INDEX.pl +16 -0
  355. package/lib/swipl/library/ext/json/http/http_json.pl +490 -0
  356. package/lib/swipl/library/ext/json/http/js_grammar.pl +53 -0
  357. package/lib/swipl/library/ext/json/http/json.pl +48 -0
  358. package/lib/swipl/library/ext/json/http/json_convert.pl +48 -0
  359. package/lib/swipl/library/ext/json/json.pl +1215 -0
  360. package/lib/swipl/library/ext/json/json_convert.pl +681 -0
  361. package/lib/swipl/library/ext/json/json_grammar.pl +349 -0
  362. package/lib/swipl/library/ext/json/json_rpc_client.pl +423 -0
  363. package/lib/swipl/library/ext/json/json_rpc_common.pl +104 -0
  364. package/lib/swipl/library/ext/json/json_rpc_server.pl +489 -0
  365. package/lib/swipl/library/ext/json/json_schema.pl +2111 -0
  366. package/lib/swipl/library/ext/nlp/INDEX.pl +15 -0
  367. package/lib/swipl/library/ext/nlp/double_metaphone.pl +86 -0
  368. package/lib/swipl/library/ext/nlp/isub.pl +162 -0
  369. package/lib/swipl/library/ext/nlp/porter_stem.pl +50 -0
  370. package/lib/swipl/library/ext/nlp/snowball.pl +97 -0
  371. package/lib/swipl/library/ext/pcre/INDEX.pl +17 -0
  372. package/lib/swipl/library/ext/pcre/pcre.pl +974 -0
  373. package/lib/swipl/library/ext/plunit/INDEX.pl +20 -0
  374. package/lib/swipl/library/ext/plunit/plunit.pl +2631 -0
  375. package/lib/swipl/library/ext/plunit/test_wizard.pl +249 -0
  376. package/lib/swipl/library/ext/semweb/semweb/INDEX.pl +288 -0
  377. package/lib/swipl/library/ext/semweb/semweb/rdf11.pl +2106 -0
  378. package/lib/swipl/library/ext/semweb/semweb/rdf11_containers.pl +299 -0
  379. package/lib/swipl/library/ext/semweb/semweb/rdf_cache.pl +278 -0
  380. package/lib/swipl/library/ext/semweb/semweb/rdf_compare.pl +132 -0
  381. package/lib/swipl/library/ext/semweb/semweb/rdf_db.pl +3468 -0
  382. package/lib/swipl/library/ext/semweb/semweb/rdf_edit.pl +1145 -0
  383. package/lib/swipl/library/ext/semweb/semweb/rdf_http_plugin.pl +274 -0
  384. package/lib/swipl/library/ext/semweb/semweb/rdf_library.pl +1021 -0
  385. package/lib/swipl/library/ext/semweb/semweb/rdf_litindex.pl +1035 -0
  386. package/lib/swipl/library/ext/semweb/semweb/rdf_ntriples.pl +422 -0
  387. package/lib/swipl/library/ext/semweb/semweb/rdf_persistency.pl +1576 -0
  388. package/lib/swipl/library/ext/semweb/semweb/rdf_portray.pl +182 -0
  389. package/lib/swipl/library/ext/semweb/semweb/rdf_prefixes.pl +681 -0
  390. package/lib/swipl/library/ext/semweb/semweb/rdf_sandbox.pl +153 -0
  391. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle.pl +54 -0
  392. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle_write.pl +1587 -0
  393. package/lib/swipl/library/ext/semweb/semweb/rdf_zlib_plugin.pl +52 -0
  394. package/lib/swipl/library/ext/semweb/semweb/rdfa.pl +1510 -0
  395. package/lib/swipl/library/ext/semweb/semweb/rdfs.pl +475 -0
  396. package/lib/swipl/library/ext/semweb/semweb/sparql_client.pl +643 -0
  397. package/lib/swipl/library/ext/semweb/semweb/turtle.pl +455 -0
  398. package/lib/swipl/library/ext/sgml/DTD/HTML4.dcl +88 -0
  399. package/lib/swipl/library/ext/sgml/DTD/HTML4.dtd +1092 -0
  400. package/lib/swipl/library/ext/sgml/DTD/HTML4.soc +6 -0
  401. package/lib/swipl/library/ext/sgml/DTD/HTML5.dtd +906 -0
  402. package/lib/swipl/library/ext/sgml/DTD/HTMLlat1.ent +195 -0
  403. package/lib/swipl/library/ext/sgml/DTD/HTMLspec.ent +77 -0
  404. package/lib/swipl/library/ext/sgml/DTD/HTMLsym.ent +241 -0
  405. package/lib/swipl/library/ext/sgml/INDEX.pl +64 -0
  406. package/lib/swipl/library/ext/sgml/c14n2.pl +203 -0
  407. package/lib/swipl/library/ext/sgml/iso_639.pl +631 -0
  408. package/lib/swipl/library/ext/sgml/pwp.pl +705 -0
  409. package/lib/swipl/library/ext/sgml/sgml.pl +815 -0
  410. package/lib/swipl/library/ext/sgml/sgml_write.pl +1003 -0
  411. package/lib/swipl/library/ext/sgml/xpath.pl +620 -0
  412. package/lib/swipl/library/ext/sgml/xsdp_types.pl +232 -0
  413. package/lib/swipl/library/ext/ssl/INDEX.pl +60 -0
  414. package/lib/swipl/library/ext/ssl/crypto.pl +1015 -0
  415. package/lib/swipl/library/ext/ssl/http/INDEX.pl +5 -0
  416. package/lib/swipl/library/ext/ssl/http/http_ssl_plugin.pl +296 -0
  417. package/lib/swipl/library/ext/ssl/saml.pl +609 -0
  418. package/lib/swipl/library/ext/ssl/ssl.pl +647 -0
  419. package/lib/swipl/library/ext/ssl/xmldsig.pl +391 -0
  420. package/lib/swipl/library/ext/ssl/xmlenc.pl +354 -0
  421. package/lib/swipl/library/ext/zlib/INDEX.pl +8 -0
  422. package/lib/swipl/library/ext/zlib/zlib.pl +112 -0
  423. package/lib/swipl/library/fastrw.pl +105 -0
  424. package/lib/swipl/library/files.pl +80 -0
  425. package/lib/swipl/library/gensym.pl +111 -0
  426. package/lib/swipl/library/git.pl +1027 -0
  427. package/lib/swipl/library/hashtable.pl +365 -0
  428. package/lib/swipl/library/heaps.pl +252 -0
  429. package/lib/swipl/library/hotfix.pl +239 -0
  430. package/lib/swipl/library/http/jquery.pl +103 -0
  431. package/lib/swipl/library/http/web/js/jquery-3.6.0.min.js +2 -0
  432. package/lib/swipl/library/increval.pl +217 -0
  433. package/lib/swipl/library/intercept.pl +263 -0
  434. package/lib/swipl/library/iostream.pl +237 -0
  435. package/lib/swipl/library/iri_scheme/file.pl +70 -0
  436. package/lib/swipl/library/lazy_lists.pl +481 -0
  437. package/lib/swipl/library/listing.pl +1362 -0
  438. package/lib/swipl/library/lists.pl +860 -0
  439. package/lib/swipl/library/lynx/INDEX.pl +14 -0
  440. package/lib/swipl/library/lynx/format.pl +380 -0
  441. package/lib/swipl/library/lynx/html_style.pl +129 -0
  442. package/lib/swipl/library/lynx/html_text.pl +865 -0
  443. package/lib/swipl/library/lynx/pldoc_style.pl +87 -0
  444. package/lib/swipl/library/macros.pl +451 -0
  445. package/lib/swipl/library/main.pl +1200 -0
  446. package/lib/swipl/library/make.pl +197 -0
  447. package/lib/swipl/library/modules.pl +129 -0
  448. package/lib/swipl/library/nb_rbtrees.pl +267 -0
  449. package/lib/swipl/library/nb_set.pl +203 -0
  450. package/lib/swipl/library/obfuscate.pl +115 -0
  451. package/lib/swipl/library/occurs.pl +241 -0
  452. package/lib/swipl/library/operators.pl +182 -0
  453. package/lib/swipl/library/option.pl +388 -0
  454. package/lib/swipl/library/optparse.pl +966 -0
  455. package/lib/swipl/library/ordsets.pl +518 -0
  456. package/lib/swipl/library/oset.pl +160 -0
  457. package/lib/swipl/library/pairs.pl +187 -0
  458. package/lib/swipl/library/persistency.pl +713 -0
  459. package/lib/swipl/library/pio.pl +47 -0
  460. package/lib/swipl/library/portray_text.pl +277 -0
  461. package/lib/swipl/library/pprint.pl +940 -0
  462. package/lib/swipl/library/predicate_options.pl +975 -0
  463. package/lib/swipl/library/prolog_autoload.pl +233 -0
  464. package/lib/swipl/library/prolog_breakpoints.pl +396 -0
  465. package/lib/swipl/library/prolog_clause.pl +1104 -0
  466. package/lib/swipl/library/prolog_code.pl +416 -0
  467. package/lib/swipl/library/prolog_codewalk.pl +1248 -0
  468. package/lib/swipl/library/prolog_colour.pl +3301 -0
  469. package/lib/swipl/library/prolog_colour.qlf +0 -0
  470. package/lib/swipl/library/prolog_config.pl +154 -0
  471. package/lib/swipl/library/prolog_coverage.pl +1333 -0
  472. package/lib/swipl/library/prolog_debug.pl +404 -0
  473. package/lib/swipl/library/prolog_deps.pl +675 -0
  474. package/lib/swipl/library/prolog_evaluable.pl +234 -0
  475. package/lib/swipl/library/prolog_format.pl +219 -0
  476. package/lib/swipl/library/prolog_history.pl +161 -0
  477. package/lib/swipl/library/prolog_jiti.pl +333 -0
  478. package/lib/swipl/library/prolog_locale.pl +61 -0
  479. package/lib/swipl/library/prolog_metainference.pl +307 -0
  480. package/lib/swipl/library/prolog_pack.pl +3906 -0
  481. package/lib/swipl/library/prolog_profile.pl +346 -0
  482. package/lib/swipl/library/prolog_qlfmake.pl +533 -0
  483. package/lib/swipl/library/prolog_source.pl +1188 -0
  484. package/lib/swipl/library/prolog_stack.pl +794 -0
  485. package/lib/swipl/library/prolog_trace.pl +365 -0
  486. package/lib/swipl/library/prolog_versions.pl +347 -0
  487. package/lib/swipl/library/prolog_wrap.pl +164 -0
  488. package/lib/swipl/library/prolog_xref.pl +3090 -0
  489. package/lib/swipl/library/prolog_xref.qlf +0 -0
  490. package/lib/swipl/library/pure_input.pl +266 -0
  491. package/lib/swipl/library/qpforeign.pl +695 -0
  492. package/lib/swipl/library/qsave.pl +1516 -0
  493. package/lib/swipl/library/quasi_quotations.pl +300 -0
  494. package/lib/swipl/library/quintus.pl +437 -0
  495. package/lib/swipl/library/random.pl +459 -0
  496. package/lib/swipl/library/rbtrees.pl +1153 -0
  497. package/lib/swipl/library/readln.pl +256 -0
  498. package/lib/swipl/library/readutil.pl +304 -0
  499. package/lib/swipl/library/record.pl +544 -0
  500. package/lib/swipl/library/rwlocks.pl +172 -0
  501. package/lib/swipl/library/sandbox.pl +1384 -0
  502. package/lib/swipl/library/semweb/dc.rdfs +198 -0
  503. package/lib/swipl/library/semweb/eor.rdfs +95 -0
  504. package/lib/swipl/library/semweb/owl.owl +287 -0
  505. package/lib/swipl/library/semweb/rdf_library.ttl +90 -0
  506. package/lib/swipl/library/semweb/rdfs.rdfs +251 -0
  507. package/lib/swipl/library/settings.pl +755 -0
  508. package/lib/swipl/library/shell.pl +462 -0
  509. package/lib/swipl/library/shlib.pl +670 -0
  510. package/lib/swipl/library/solution_sequences.pl +439 -0
  511. package/lib/swipl/library/sort.pl +119 -0
  512. package/lib/swipl/library/statistics.pl +541 -0
  513. package/lib/swipl/library/streams.pl +118 -0
  514. package/lib/swipl/library/strings.pl +469 -0
  515. package/lib/swipl/library/system.pl +95 -0
  516. package/lib/swipl/library/tables.pl +381 -0
  517. package/lib/swipl/library/tableutil.pl +771 -0
  518. package/lib/swipl/library/tabling.pl +42 -0
  519. package/lib/swipl/library/terms.pl +457 -0
  520. package/lib/swipl/library/theme/auto.pl +61 -0
  521. package/lib/swipl/library/theme/dark.pl +455 -0
  522. package/lib/swipl/library/theme/light.pl +45 -0
  523. package/lib/swipl/library/thread.pl +810 -0
  524. package/lib/swipl/library/thread_pool.pl +508 -0
  525. package/lib/swipl/library/threadutil.pl +574 -0
  526. package/lib/swipl/library/tty.pl +316 -0
  527. package/lib/swipl/library/ugraphs.pl +644 -0
  528. package/lib/swipl/library/unicode/INDEX.pl +6 -0
  529. package/lib/swipl/library/unicode/blocks.pl +414 -0
  530. package/lib/swipl/library/url.pl +1129 -0
  531. package/lib/swipl/library/utf8.pl +145 -0
  532. package/lib/swipl/library/varnumbers.pl +221 -0
  533. package/lib/swipl/library/vm.pl +251 -0
  534. package/lib/swipl/library/wfs.pl +205 -0
  535. package/lib/swipl/library/when.pl +263 -0
  536. package/lib/swipl/library/writef.pl +278 -0
  537. package/lib/swipl/library/www_browser.pl +251 -0
  538. package/lib/swipl/library/yall.pl +574 -0
  539. package/lib/swipl/library/zip.pl +211 -0
  540. package/lib/swipl/swipl.home +1 -0
  541. package/lib/vendor/libcrypto.so.3 +0 -0
  542. package/lib/vendor/libpcre2-8.so.0 +0 -0
  543. package/lib/vendor/libssl.so.3 +0 -0
  544. package/lib/vendor/libz.so.1 +0 -0
  545. package/licenses/OpenSSL-LICENSE.txt +177 -0
  546. package/licenses/PCRE2-COPYING +5 -0
  547. package/licenses/README.md +12 -0
  548. package/licenses/SWI-Prolog-LICENSE +41 -0
  549. package/licenses/zlib-LICENSE +22 -0
  550. package/package.json +27 -0
@@ -0,0 +1,2106 @@
1
+ /* Part of SWI-Prolog
2
+
3
+ Author: Jan Wielemaker and Wouter Beek
4
+ E-mail: J.Wielemaker@vu.nl
5
+ WWW: http://www.swi-prolog.org
6
+ Copyright (c) 2015-2018, VU University Amsterdam
7
+ CWI, Amsterdam
8
+ All rights reserved.
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions
12
+ are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright
15
+ notice, this list of conditions and the following disclaimer.
16
+
17
+ 2. Redistributions in binary form must reproduce the above copyright
18
+ notice, this list of conditions and the following disclaimer in
19
+ the documentation and/or other materials provided with the
20
+ distribution.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
+ POSSIBILITY OF SUCH DAMAGE.
34
+ */
35
+
36
+
37
+ :- module(rdf11,
38
+ [ rdf/3, % ?S, ?P, ?O
39
+ rdf/4, % ?S, ?P, ?O, ?G
40
+ rdf_has/3, % ?S, ?P, ?O
41
+ rdf_has/4, % ?S, ?P, ?O, -RealP
42
+ rdf_update/4, % +S, +P, +O, +Action
43
+ rdf_update/5, % +S, +P, +O, +G, +Action
44
+ rdf_reachable/3, % ?S, ?P, ?O
45
+ rdf_reachable/5, % ?S, ?P, ?O, +MaxD, -D
46
+
47
+ rdf_assert/3, % +S, +P, +O
48
+ rdf_assert/4, % +S, +P, +O, ?G
49
+ rdf_retractall/3, % ?S, ?P, ?O
50
+ rdf_retractall/4, % ?S, ?P, ?O, ?G
51
+
52
+ {}/1, % +Where
53
+ rdf_where/1, % +Where
54
+ rdf_compare/3, % -Diff, +Left, +Right
55
+
56
+ rdf_term/1, % ?Term
57
+ rdf_literal/1, % ?Term
58
+ rdf_bnode/1, % ?Term
59
+ rdf_iri/1, % ?Term
60
+ rdf_name/1, % ?Term
61
+
62
+ rdf_is_iri/1, % @Term
63
+ rdf_is_bnode/1, % @Term
64
+ rdf_is_literal/1, % @Term
65
+ rdf_is_name/1, % @Term
66
+ rdf_is_object/1, % @Term
67
+ rdf_is_predicate/1, % @Term
68
+ rdf_is_subject/1, % @Term
69
+ rdf_is_term/1, % @Term
70
+
71
+ rdf_subject/1, % ?Term
72
+ rdf_predicate/1, % ?Term
73
+ rdf_object/1, % ?Term
74
+ rdf_node/1, % ?Term
75
+
76
+ rdf_create_bnode/1, % ?Term
77
+
78
+ rdf_canonical_literal/2, % +In, -Canonical
79
+ rdf_lexical_form/2, % +Literal, -Lexical
80
+
81
+ rdf_default_graph/1, % -Graph
82
+ rdf_default_graph/2, % -Old, +New
83
+
84
+ rdf_estimate_complexity/4, % ?S, ?P, ?O, -Estimate
85
+ rdf_assert_list/2, % +PrologList, ?RDFList
86
+ rdf_assert_list/3, % +PrologList, ?RDFList, +G
87
+ rdf_last/2, % +RDFList, ?Last
88
+ rdf_list/1, % ?RDFList
89
+ rdf_list/2, % +RDFList, -PrologList
90
+ rdf_length/2, % ?RDFList, ?Length
91
+ rdf_member/2, % ?Member, +RDFList
92
+ rdf_nextto/2, % ?X, ?Y
93
+ rdf_nextto/3, % ?X, ?Y, ?RdfList
94
+ rdf_nth0/3, % ?Index, +RDFList, ?X
95
+ rdf_nth1/3, % ?Index, +RDFList, ?X
96
+ rdf_retract_list/1, % +RDFList
97
+
98
+ op(110, xfx, @), % must be above .
99
+ op(650, xfx, ^^), % must be above :
100
+ op(1150, fx, rdf_meta)
101
+ ]).
102
+ :- use_module(library(semweb/rdf_prefixes),
103
+ [ (rdf_meta)/1, op(_,_,rdf_meta)
104
+ ]).
105
+ :- use_module(library(semweb/rdf_db),
106
+ [ rdf_transaction/2,
107
+ rdf_match_label/3,
108
+ rdf_equal/2,
109
+ rdf_is_bnode/1,
110
+ rdf_transaction/1
111
+ ]).
112
+
113
+ :- autoload(library(apply),[partition/4]).
114
+ :- autoload(library(c14n2),[xml_write_canonical/3]).
115
+ :- use_module(library(debug),[assertion/1,debug/3]).
116
+ :- autoload(library(error),
117
+ [ must_be/2,
118
+ domain_error/2,
119
+ instantiation_error/1,
120
+ existence_error/2,
121
+ type_error/2,
122
+ is_of_type/2,
123
+ uninstantiation_error/1
124
+ ]).
125
+ :- autoload(library(lists),[select/3,append/3]).
126
+ :- autoload(library(memfile),
127
+ [new_memory_file/1,open_memory_file/3,free_memory_file/1]).
128
+ :- autoload(library(sgml),
129
+ [ xsd_number_string/2,
130
+ xsd_time_string/3,
131
+ xml_is_dom/1,
132
+ load_xml/3,
133
+ load_html/3
134
+ ]).
135
+ :- autoload(library(sgml_write),[html_write/3,xml_write/2]).
136
+ :- autoload(library(solution_sequences),[distinct/2]).
137
+
138
+ :- reexport(library(semweb/rdf_db),
139
+ except([ rdf/3,
140
+ rdf/4,
141
+ rdf_assert/3,
142
+ rdf_assert/4,
143
+ rdf_current_literal/1,
144
+ rdf_current_predicate/1,
145
+ rdf_has/3,
146
+ rdf_has/4,
147
+ rdf_update/4,
148
+ rdf_update/5,
149
+ rdf_reachable/3,
150
+ rdf_reachable/5,
151
+ rdf_retractall/3,
152
+ rdf_retractall/4,
153
+ rdf_node/1,
154
+ rdf_bnode/1,
155
+ rdf_is_literal/1,
156
+ rdf_is_resource/1,
157
+ rdf_literal_value/2,
158
+ rdf_compare/3,
159
+ rdf_estimate_complexity/4
160
+ ])
161
+ ).
162
+ /** <module> RDF 1.1 API
163
+
164
+ This library provides a new API on top of library(semweb/rdf_db). The
165
+ new API follows the RDF 1.1 terminology and notation as much as
166
+ possible. It runs on top of the old API, which implies that applications
167
+ can use the new API in one file and the other in another one. Once the
168
+ new API is considered stable and robust the old API will be deprecated.
169
+
170
+ In a nutshell, the following issues are addressed:
171
+
172
+ - Literals are now represented by Value^^Type or Text@Lang. Plain
173
+ literals no longer exist. Value is a Prolog representation of
174
+ the value for known types. In particular:
175
+ - xsd:double, xsd:float and xsd:decimal are represented by a Prolog
176
+ float
177
+ - Integer types are represented by a Prolog integer
178
+ - The date/time types are presented by Prolog terms
179
+ - Literal matching and comparison operations are represented as
180
+ Prolog _constraints_. This replaces the literal(+Search,-Value)
181
+ construct used by library(semweb/rdf_db). For example, the following
182
+ query returns literals with prefix "ams", exploiting the RDF literal
183
+ index.
184
+
185
+ ==
186
+ { prefix(Name, "ams") },
187
+ rdf(S,P,Name).
188
+ ==
189
+ - Graphs are always identified by the graph name only, i.e., the
190
+ notation Graph:Line is no longer supported. If a graph name is an IRI
191
+ then RDF prefix notation can now be used.
192
+ - The enumeration and type-testing predicates are now more closely based
193
+ on the RDF 1.1 specification and use consistent naming.
194
+
195
+ @author Jan Wielemaker
196
+ @author Wouter Beek
197
+ @see https://github.com/SWI-Prolog/packages-semweb/wiki/Proposal-for-Semweb-library-redesign
198
+ @version 2016
199
+ */
200
+
201
+ :- multifile
202
+ in_ground_type_hook/3, % +Type, +Input, -Lexical:atom
203
+ out_type_hook/3, % +Type, -Output, +Lexical:atom
204
+ invalid_lexical_form_hook/3. % +Type, +Lexical, -Prolog
205
+
206
+ :- meta_predicate
207
+ parse_partial_xml(3,+,-).
208
+
209
+ :- rdf_meta
210
+ rdf(r,r,o),
211
+ rdf(r,r,o,r),
212
+ rdf_assert(r,r,o),
213
+ rdf_assert(r,r,o,r),
214
+ rdf_has(r,r,o),
215
+ rdf_has(r,r,o,-),
216
+ rdf_update(r,r,o,t),
217
+ rdf_update(r,r,o,r,t),
218
+ rdf_reachable(r,r,o),
219
+ rdf_reachable(r,r,o,+,-),
220
+ rdf_retractall(r,r,o),
221
+ rdf_retractall(r,r,o,r),
222
+ {}(t),
223
+ rdf_where(t),
224
+ rdf_canonical_literal(o,-),
225
+ rdf_lexical_form(o,-),
226
+ rdf_compare(-,o,o),
227
+ rdf_iri(r),
228
+ rdf_is_iri(r),
229
+ rdf_is_literal(o),
230
+ rdf_is_name(o),
231
+ rdf_is_object(o),
232
+ rdf_is_predicate(r),
233
+ rdf_is_subject(r),
234
+ rdf_is_term(o),
235
+ rdf_term(o),
236
+ rdf_literal(o),
237
+ rdf_name(o),
238
+ rdf_object(o),
239
+ rdf_estimate_complexity(r,r,o,-),
240
+ rdf_assert_list(t,r),
241
+ rdf_assert_list(t,r,r),
242
+ rdf_last(r,o),
243
+ rdf_list(r),
244
+ rdf_list(r,-),
245
+ rdf_length(r,-),
246
+ rdf_member(o,r),
247
+ rdf_nextto(o,o),
248
+ rdf_nth0(?,r,o),
249
+ rdf_nth1(?,r,o),
250
+ rdf_retract_list(r).
251
+
252
+
253
+ %! rdf(?S, ?P, ?O) is nondet.
254
+ %! rdf(?S, ?P, ?O, ?G) is nondet.
255
+ %
256
+ % True if an RDF triple <S,P,O> exists, optionally in the graph G.
257
+ % The object O is either a resource (atom) or one of the terms
258
+ % listed below. The described types apply for the case where O is
259
+ % unbound. If O is instantiated it is converted according to the
260
+ % rules described with rdf_assert/3.
261
+ %
262
+ % Triples consist of the following three terms:
263
+ %
264
+ % - Blank nodes are encoded by atoms that start with `_:`.
265
+ % - IRIs appear in two notations:
266
+ % - Full IRIs are encoded by atoms that do not start with
267
+ % `_:`. Specifically, an IRI term is not required to follow
268
+ % the IRI standard grammar.
269
+ % - Abbreviated IRI notation that allows IRI prefix aliases
270
+ % that are registered by rdf_register_prefix/[2,3] to be
271
+ % used. Their notation is `Alias:Local`, where Alias and
272
+ % Local are atoms. Each abbreviated IRI is expanded by the
273
+ % system to a full IRI.
274
+ % - Literals appear in two notations:
275
+ % - String@Lang
276
+ % A language-tagged string, where String is a Prolog string
277
+ % and Lang is an atom.
278
+ % - Value^^Type
279
+ % A type qualified literal. For unknown types, Value is a
280
+ % Prolog string. If type is known, the Prolog representations
281
+ % from the table below are used.
282
+ %
283
+ % | **Datatype IRI** | **Prolog term** |
284
+ % |:----------------------|:--------------------------------|
285
+ % | xsd:float | float |
286
+ % | xsd:double | float |
287
+ % | xsd:decimal | float (1) |
288
+ % | xsd:integer | integer |
289
+ % | XSD integer sub-types | integer |
290
+ % | xsd:boolean | `true` or `false` |
291
+ % | xsd:date | date(Y,M,D) |
292
+ % | xsd:dateTime | date_time(Y,M,D,HH,MM,SS) (2,3) |
293
+ % | xsd:gDay | integer |
294
+ % | xsd:gMonth | integer |
295
+ % | xsd:gMonthDay | month_day(M,D) |
296
+ % | xsd:gYear | integer |
297
+ % | xsd:gYearMonth | year_month(Y,M) |
298
+ % | xsd:time | time(HH,MM,SS) (2) |
299
+ %
300
+ % Notes:
301
+ %
302
+ % (1) The current implementation of `xsd:decimal` values
303
+ % as floats is formally incorrect. Future versions
304
+ % of SWI-Prolog may introduce decimal as a subtype
305
+ % of rational.
306
+ %
307
+ % (2) `SS` fields denote the number of seconds. This can
308
+ % either be an integer or a float.
309
+ %
310
+ % (3) The `date_time` structure can have a 7th field that
311
+ % denotes the timezone offset *in seconds* as an
312
+ % integer.
313
+ %
314
+ % In addition, a _ground_ object value is translated into a
315
+ % properly typed RDF literal using rdf_canonical_literal/2.
316
+ %
317
+ % There is a fine distinction in how duplicate statements are
318
+ % handled in rdf/[3,4]: backtracking over rdf/3 will never return
319
+ % duplicate triples that appear in multiple graphs. rdf/4 will
320
+ % return such duplicate triples, because their graph term differs.
321
+ %
322
+ % @arg S is the subject term. It is either a blank node or IRI.
323
+ % @arg P is the predicate term. It is always an IRI.
324
+ % @arg O is the object term. It is either a literal, a blank
325
+ % node or IRI (except for `true` and `false` that denote the
326
+ % values of datatype XSD boolean).
327
+ % @arg G is the graph term. It is always an IRI.
328
+ %
329
+ % @see [Triple pattern querying](http://www.w3.org/TR/sparql11-query/#sparqlTriplePatterns)
330
+ % @see xsd_number_string/2 and xsd_time_string/3 are used to
331
+ % convert between lexical representations and Prolog terms.
332
+
333
+ rdf(S,P,O) :-
334
+ pre_object(O,O0,S,P),
335
+ rdf_db:rdf(S,P,O0),
336
+ post_object(O,O0).
337
+
338
+ rdf(S,P,O,G) :-
339
+ pre_object(O,O0,S,P),
340
+ pre_graph(G,G0),
341
+ rdf_db:rdf(S,P,O0,G0),
342
+ post_graph(G, G0),
343
+ post_object(O,O0).
344
+
345
+ %! rdf_has(?S, +P, ?O) is nondet.
346
+ %! rdf_has(?S, +P, ?O, -RealP) is nondet.
347
+ %
348
+ % Similar to rdf/3 and rdf/4, but P matches all predicates that
349
+ % are defined as an rdfs:subPropertyOf of P. This predicate also
350
+ % recognises the predicate properties `inverse_of` and
351
+ % `symmetric`. See rdf_set_predicate/2.
352
+
353
+ rdf_has(S,P,O) :-
354
+ pre_object(O,O0,S,P),
355
+ rdf_db:rdf_has(S,P,O0),
356
+ post_object(O,O0).
357
+
358
+ rdf_has(S,P,O,RealP) :-
359
+ pre_object(O,O0,S,P),
360
+ rdf_db:rdf_has(S,P,O0,RealP),
361
+ post_object(O,O0).
362
+
363
+
364
+ %! rdf_update(+S, +P, +O, ++Action) is det.
365
+ %! rdf_update(+S, +P, +O, +G, ++Action) is det.
366
+ %
367
+ % Replaces one of the three (four) fields on the matching triples
368
+ % depending on Action:
369
+ %
370
+ % * subject(Resource)
371
+ % Changes the first field of the triple.
372
+ % * predicate(Resource)
373
+ % Changes the second field of the triple.
374
+ % * object(Object)
375
+ % Changes the last field of the triple to the given resource or
376
+ % literal(Value).
377
+ % * graph(Graph)
378
+ % Moves the triple from its current named graph to Graph.
379
+ % This only works with rdf_update/5 and throws an error when
380
+ % used with rdf_update/4.
381
+ %
382
+ % The argument matching Action must be ground. If this argument is
383
+ % equivalent to the current value, no action is performed. Otherwise,
384
+ % the requested action is performed on all matching triples. For
385
+ % example, all resources typed `rdfs:Class` can be changed to
386
+ % `owl:Class` using
387
+ %
388
+ % ```
389
+ % ?- rdf_update(_, rdf:type, rdfs:'Class',
390
+ % object(owl:'Class')).
391
+ % ```
392
+ %
393
+ % @error instantiation_error if Action or the matching argument is
394
+ % not ground.
395
+ % @error domain_error(rdf_update_action, Action) if Action is not
396
+ % one of the above terms.
397
+
398
+ rdf_update(S, P, O, Action) :-
399
+ rdf_update(S, P, O, _, Action).
400
+ rdf_update(S, P, O, G, Action) :-
401
+ must_be(ground, Action),
402
+ ( update_column(Action, S,P,O,G, On)
403
+ -> must_be(ground, On),
404
+ arg(1, Action, Old),
405
+ ( On == Old
406
+ -> true
407
+ ; rdf_transaction(rdf_update_(S, P, O, G, Action), update)
408
+ )
409
+ ; domain_error(rdf_update_action, Action)
410
+ ).
411
+
412
+ update_column(subject(_), S,_,_,_, S).
413
+ update_column(predicate(_), _,P,_,_, P).
414
+ update_column(object(_), _,_,O,_, O).
415
+ update_column(graph(_), _,_,_,G, G).
416
+
417
+ rdf_update_(S1, P, O, G, subject(S2)) :-
418
+ !,
419
+ forall(rdf(S1, P, O, G),
420
+ ( rdf_retractall(S1, P, O, G),
421
+ rdf_assert(S2, P, O, G)
422
+ )).
423
+ rdf_update_(S, P1, O, G, predicate(P2)) :-
424
+ !,
425
+ forall(rdf(S, P1, O, G),
426
+ ( rdf_retractall(S, P1, O, G),
427
+ rdf_assert(S, P2, O, G)
428
+ )).
429
+ rdf_update_(S, P, O1, G, object(O2)) :-
430
+ !,
431
+ forall(rdf(S, P, O1, G),
432
+ ( rdf_retractall(S, P, O1, G),
433
+ rdf_assert(S, P, O2, G)
434
+ )).
435
+ rdf_update_(S, P, O, G1, graph(G2)) :-
436
+ !,
437
+ forall(rdf(S, P, O, G1),
438
+ ( rdf_retractall(S, P, O, G1),
439
+ rdf_assert(S, P, O, G2)
440
+ )).
441
+
442
+
443
+ %! rdf_reachable(?S, +P, ?O) is nondet.
444
+ %! rdf_reachable(?S, +P, ?O, +MaxD, -D) is nondet.
445
+ %
446
+ % True when O can be reached from S using the transitive closure
447
+ % of P. The predicate uses (the internals of) rdf_has/3 and thus
448
+ % matches both rdfs:subPropertyOf and the `inverse_of` and
449
+ % `symmetric` predicate properties. The version rdf_reachable/5
450
+ % maximizes the steps considered and returns the number of steps
451
+ % taken.
452
+ %
453
+ % If both S and O are given, these predicates are `semidet`. The
454
+ % number of steps D is minimal because the implementation uses
455
+ % _breadth first_ search.
456
+
457
+ rdf_reachable(S,P,O) :-
458
+ pre_object(O,O0,S,P),
459
+ rdf_db:rdf_reachable(S,P,O0),
460
+ post_object(O,O0).
461
+
462
+ rdf_reachable(S,P,O,MaxD,D) :-
463
+ pre_object(O,O0,S,P),
464
+ rdf_db:rdf_reachable(S,P,O0,MaxD,D),
465
+ post_object(O,O0).
466
+
467
+
468
+ %! rdf_assert(+S, +P, +O) is det.
469
+ %! rdf_assert(+S, +P, +O, +G) is det.
470
+ %
471
+ % Assert a new triple. If O is a literal, certain Prolog terms are
472
+ % translated to typed RDF literals. These conversions are
473
+ % described with rdf_canonical_literal/2.
474
+ %
475
+ % If a type is provided using Value^^Type syntax, additional
476
+ % conversions are performed. All types accept either an atom or
477
+ % Prolog string holding a valid RDF lexical value for the type and
478
+ % xsd:float and xsd:double accept a Prolog integer.
479
+
480
+ rdf_assert(S,P,O) :-
481
+ rdf_default_graph(G),
482
+ rdf_assert(S,P,O,G).
483
+
484
+ rdf_assert(S,P,O,G) :-
485
+ must_be(ground, O),
486
+ pre_ground_object(O,O0),
487
+ rdf_db:rdf_assert(S,P,O0,G).
488
+
489
+ %! rdf_retractall(?S, ?P, ?O) is nondet.
490
+ %! rdf_retractall(?S, ?P, ?O, ?G) is nondet.
491
+ %
492
+ % Remove all matching triples from the database. Matching is
493
+ % performed using the same rules as rdf/3. The call does not
494
+ % instantiate any of its arguments.
495
+
496
+ rdf_retractall(S,P,O) :-
497
+ pre_object(O,O0,S,P),
498
+ rdf_db:rdf_retractall(S,P,O0).
499
+
500
+ rdf_retractall(S,P,O,G) :-
501
+ pre_object(O,O0,S,P),
502
+ pre_graph(G,G0),
503
+ rdf_db:rdf_retractall(S,P,O0,G0).
504
+
505
+
506
+ %! rdf_compare(-Diff, +Left, +Right) is det.
507
+ %
508
+ % True if the RDF terms Left and Right are ordered according to
509
+ % the comparison operator Diff. The ordering is defines as:
510
+ %
511
+ % - Literal < BNode < IRI
512
+ % - For literals
513
+ % - Numeric < non-numeric
514
+ % - Numeric literals are ordered by value. If both are
515
+ % equal, floats are ordered before integers.
516
+ % - Other data types are ordered lexicographically.
517
+ % - BNodes and IRIs are ordered lexicographically.
518
+ %
519
+ % Note that this ordering is a complete ordering of RDF terms that
520
+ % is consistent with the partial ordering defined by SPARQL.
521
+ %
522
+ % @arg Diff is one of `<`, `=` or `>`
523
+
524
+ rdf_compare(Diff, Left, Right) :-
525
+ pre_ground_object(Left, Left0),
526
+ pre_ground_object(Right, Right0),
527
+ rdf_db:rdf_compare(Diff, Left0, Right0).
528
+
529
+
530
+ %! {}(+Where) is semidet.
531
+ %! rdf_where(+Where) is semidet.
532
+ %
533
+ % Formulate constraints on RDF terms, notably literals. These are
534
+ % intended to be used as illustrated below. RDF constraints are
535
+ % pure: they may be placed before, after or inside a graph pattern
536
+ % and, provided the code contains no _commit_ operations (!, ->),
537
+ % the semantics of the goal remains the same. Preferably,
538
+ % constraints are placed _before_ the graph pattern as they often
539
+ % help the RDF database to exploit its literal indexes. In the
540
+ % example below, the database can choose between using the subject
541
+ % and/or predicate hash or the ordered literal table.
542
+ %
543
+ % ==
544
+ % { Date >= "2000-01-01"^^xsd:date },
545
+ % rdf(S, P, Date)
546
+ % ==
547
+ %
548
+ % The following constraints are currently defined:
549
+ %
550
+ % - >, >=, ==, =<, <
551
+ % The comparison operators are defined between numbers (of any
552
+ % recognised type), typed literals of the same type and
553
+ % langStrings of the same language.
554
+ % - prefix(String, Pattern)
555
+ % - substring(String, Pattern)
556
+ % - word(String, Pattern)
557
+ % - like(String, Pattern)
558
+ % - icase(String, Pattern)
559
+ % Text matching operators that act on both typed literals
560
+ % and langStrings.
561
+ % - lang_matches(Term, Pattern)
562
+ % Demands a full RDF term (Text@Lang) or a plain `Lang` term
563
+ % to match the language pattern Pattern.
564
+ %
565
+ % The predicates rdf_where/1 and {}/1 are identical. The
566
+ % rdf_where/1 variant is provided to avoid ambiguity in
567
+ % applications where {}/1 is used for other purposes. Note that it
568
+ % is also possible to write `rdf11:{...}`.
569
+
570
+ {}(Where) :-
571
+ rdf_where(Where).
572
+
573
+ rdf_where(Var) :-
574
+ var(Var),
575
+ !,
576
+ instantiation_error(Var).
577
+ rdf_where((A,B)) :-
578
+ !,
579
+ rdf_where(A),
580
+ rdf_where(B).
581
+ rdf_where(Constraint) :-
582
+ rdf_constraint(Constraint, Goal),
583
+ !,
584
+ call(Goal).
585
+ rdf_where(Constraint) :-
586
+ existence_error(rdf_constraint, Constraint).
587
+
588
+ % Comparison operators
589
+ rdf_constraint(Term >= Value,
590
+ add_value_constraint(Term, >=, Value)).
591
+ rdf_constraint(Term > Value,
592
+ add_value_constraint(Term, >, Value)).
593
+ rdf_constraint(Term == Value,
594
+ add_value_constraint(Term, ==, Value)).
595
+ rdf_constraint(Term < Value,
596
+ add_value_constraint(Term, <, Value)).
597
+ rdf_constraint(Term =< Value,
598
+ add_value_constraint(Term, =<, Value)).
599
+ % String selection
600
+ rdf_constraint(prefix(Term, Pattern),
601
+ add_text_constraint(Term, prefix(PatternA))) :-
602
+ atom_string(PatternA, Pattern).
603
+ rdf_constraint(substring(Term, Pattern),
604
+ add_text_constraint(Term, substring(PatternA))) :-
605
+ atom_string(PatternA, Pattern).
606
+ rdf_constraint(word(Term, Pattern),
607
+ add_text_constraint(Term, word(PatternA))) :-
608
+ atom_string(PatternA, Pattern).
609
+ rdf_constraint(like(Term, Pattern),
610
+ add_text_constraint(Term, like(PatternA))) :-
611
+ atom_string(PatternA, Pattern).
612
+ rdf_constraint(icase(Term, Pattern),
613
+ add_text_constraint(Term, icase(PatternA))) :-
614
+ atom_string(PatternA, Pattern).
615
+ % Lang selection
616
+ rdf_constraint(lang_matches(Term, Pattern),
617
+ add_lang_constraint(Term, lang_matches(Pattern))).
618
+
619
+ add_text_constraint(Var, Cond) :-
620
+ var(Var),
621
+ !,
622
+ ( get_attr(Var, rdf11, Cond0)
623
+ -> put_attr(Var, rdf11, [Cond|Cond0])
624
+ ; put_attr(Var, rdf11, [Cond])
625
+ ).
626
+ add_text_constraint(Text^^_Type, Cond) :-
627
+ !,
628
+ add_text_constraint(Text, Cond).
629
+ add_text_constraint(Text@_Lang, Cond) :-
630
+ !,
631
+ add_text_constraint(Text, Cond).
632
+ add_text_constraint(Var, Cond) :-
633
+ eval_condition(Cond, Var).
634
+
635
+ %! add_lang_constraint(?Term, +Constraint)
636
+ %
637
+ % Add a constraint on the language of a literal
638
+
639
+ add_lang_constraint(Var, Constraint) :-
640
+ var(Var),
641
+ !,
642
+ ( get_attr(Var, rdf11, Cond0)
643
+ -> put_attr(Var, rdf11, [Constraint|Cond0])
644
+ ; put_attr(Var, rdf11, [Constraint])
645
+ ).
646
+ add_lang_constraint(_Text@Lang, Constraint) :-
647
+ !,
648
+ add_lang_constraint(Lang, Constraint).
649
+ add_lang_constraint(_Text^^_Type, _Constraint) :-
650
+ !,
651
+ fail.
652
+ add_lang_constraint(Term, Constraint) :-
653
+ eval_condition(Constraint, Term).
654
+
655
+ %! add_value_constraint(?Term, +Constraint, +Value)
656
+ %
657
+ % Apply a value constraint to the RDF Term.
658
+
659
+ add_value_constraint(Term, Constraint, ValueIn) :-
660
+ constraint_literal_value(ValueIn, Value),
661
+ add_value_constraint_cann(Value, Constraint, Term).
662
+
663
+ constraint_literal_value(Value, Value^^_Type) :-
664
+ number(Value),
665
+ !.
666
+ constraint_literal_value(Value, Literal) :-
667
+ rdf_canonical_literal(Value, Literal).
668
+
669
+ add_value_constraint_cann(RefVal^^Type, Constraint, Term) :-
670
+ var(Term), var(Type),
671
+ !,
672
+ add_text_constraint(Term, value(Constraint, RefVal, Type)).
673
+ add_value_constraint_cann(RefVal^^Type, Constraint, Val^^Type2) :-
674
+ !,
675
+ Type = Type2,
676
+ add_text_constraint(Val, value(Constraint, RefVal, Type)).
677
+ add_value_constraint_cann(RefVal@Lang, Constraint, Val@Lang) :-
678
+ !,
679
+ add_text_constraint(Val, value(Constraint, RefVal, lang(Lang))).
680
+ add_value_constraint_cann(RefVal^^Type, Constraint, Val) :-
681
+ !,
682
+ ground(Val),
683
+ Val \= _@_,
684
+ eval_condition(value(Constraint, RefVal, Type), Val).
685
+
686
+ put_cond(Var, []) :-
687
+ !,
688
+ del_attr(Var, rdf11).
689
+ put_cond(Var, List) :-
690
+ put_attr(Var, rdf11, List).
691
+
692
+ eval_condition(Cond, Literal) :-
693
+ text_condition(Cond),
694
+ !,
695
+ text_of(Literal, Text),
696
+ text_condition(Cond, Text).
697
+ eval_condition(Cond, Literal) :-
698
+ lang_condition(Cond),
699
+ !,
700
+ lang_of(Literal, Lang),
701
+ lang_condition(Cond, Lang).
702
+ eval_condition(value(Comp, Ref, _Type), Value) :-
703
+ ( number(Ref)
704
+ -> number(Value),
705
+ compare_numeric(Comp, Ref, Value)
706
+ ; compare_std(Comp, Ref, Value)
707
+ ).
708
+
709
+ compare_numeric(<, Ref, Value) :- Value < Ref.
710
+ compare_numeric(=<, Ref, Value) :- Value =< Ref.
711
+ compare_numeric(==, Ref, Value) :- Value =:= Ref.
712
+ compare_numeric(>=, Ref, Value) :- Value >= Ref.
713
+ compare_numeric( >, Ref, Value) :- Value > Ref.
714
+
715
+ compare_std(<, Ref, Value) :- Value @< Ref.
716
+ compare_std(=<, Ref, Value) :- Value @=< Ref.
717
+ compare_std(==, Ref, Value) :- Value == Ref.
718
+ compare_std(>=, Ref, Value) :- Value @>= Ref.
719
+ compare_std( >, Ref, Value) :- Value @> Ref.
720
+
721
+ text_condition(prefix(_)).
722
+ text_condition(substring(_)).
723
+ text_condition(word(_)).
724
+ text_condition(like(_)).
725
+ text_condition(icase(_)).
726
+
727
+ text_of(Literal, Text) :-
728
+ atomic(Literal),
729
+ !,
730
+ Text = Literal.
731
+ text_of(Text@_Lang, Text).
732
+ text_of(Text^^_Type, Text).
733
+
734
+ text_condition(prefix(Pattern), Text) :-
735
+ rdf_match_label(prefix, Pattern, Text).
736
+ text_condition(substring(Pattern), Text) :-
737
+ rdf_match_label(substring, Pattern, Text).
738
+ text_condition(word(Pattern), Text) :-
739
+ rdf_match_label(word, Pattern, Text).
740
+ text_condition(like(Pattern), Text) :-
741
+ rdf_match_label(like, Pattern, Text).
742
+ text_condition(icase(Pattern), Text) :-
743
+ rdf_match_label(icase, Pattern, Text).
744
+
745
+ lang_condition(lang_matches(_)).
746
+
747
+ lang_of(_Text@Lang0, Lang) :-
748
+ !,
749
+ Lang = Lang0.
750
+ lang_of(Lang, Lang) :-
751
+ atom(Lang).
752
+
753
+ lang_condition(lang_matches(Pattern), Lang) :-
754
+ rdf_db:lang_matches(Lang, Pattern).
755
+
756
+ %! literal_condition(+Object, -Cond) is semidet.
757
+ %
758
+ % True when some of the constraints on Object can be translated
759
+ % into an equivalent query of the form literal(Cond, _Value).
760
+ % Translated constraints are removed from object.
761
+
762
+ literal_condition(Object, Cond) :-
763
+ get_attr(Object, rdf11, Cond0),
764
+ best_literal_cond(Cond0, Cond, Rest),
765
+ put_cond(Object, Rest).
766
+
767
+ %! best_literal_cond(+Conditions, -Best, -Rest) is semidet.
768
+ %
769
+ % Extract the constraints that can be translated into the _Search_
770
+ % of literal(Search, Value).
771
+ %
772
+ % @tbd Select the best rather than the first.
773
+
774
+ best_literal_cond(Conditions, Best, Rest) :-
775
+ sort(Conditions, Unique),
776
+ best_literal_cond2(Unique, Best, Rest).
777
+
778
+ best_literal_cond2(Conds, Best, Rest) :-
779
+ select(Cond, Conds, Rest0),
780
+ rdf10_cond(Cond, Best, Rest0, Rest),
781
+ !.
782
+
783
+ rdf10_cond(value(=<, URef, UType), Cond, Rest0, Rest) :-
784
+ ( select(value(>=, LRef, LType), Rest0, Rest)
785
+ -> true
786
+ ; memberchk(value(>, LRef, LType), Rest0)
787
+ -> Rest = Rest0
788
+ ),
789
+ !,
790
+ in_constaint_type(LType, SLType, LRef, LRef0),
791
+ in_constaint_type(UType, SUType, URef, URef0),
792
+ Cond = between(type(SLType, LRef0), type(SUType, URef0)).
793
+ rdf10_cond(value(<, URef, UType), Cond, Rest0, Rest) :-
794
+ ( select(value(>=, LRef, LType), Rest0, Rest1)
795
+ -> true
796
+ ; memberchk(value(>, LRef, LType), Rest0)
797
+ -> Rest1 = Rest0
798
+ ),
799
+ !,
800
+ Rest = [value(<, URef, UType)|Rest1],
801
+ in_constaint_type(LType, SLType, LRef, LRef0),
802
+ in_constaint_type(UType, SUType, URef, URef0),
803
+ Cond = between(type(SLType, LRef0), type(SUType, URef0)).
804
+ rdf10_cond(value(Cmp, Ref, Type), Pattern, Rest, Rest) :-
805
+ !,
806
+ rdf10_compare(Cmp, Ref, Type, Pattern).
807
+ rdf10_cond(lang_matches(_), _, _, _) :- !, fail.
808
+ rdf10_cond(Cond, Cond, Rest, Rest).
809
+
810
+ rdf10_compare(Cmp, Ref, Type, Pattern) :-
811
+ nonvar(Type), Type = lang(Lang),
812
+ !,
813
+ atom_string(Ref0, Ref),
814
+ rdf10_lang_cond(Cmp, Ref0, Lang, Pattern).
815
+ rdf10_compare(Cmp, Ref, Type, Pattern) :-
816
+ in_constaint_type(Type, SType, Ref, Ref0),
817
+ rdf10_type_cond(Cmp, Ref0, SType, Pattern).
818
+
819
+ rdf10_lang_cond( <, Ref, Lang, lt(lang(Lang,Ref))).
820
+ rdf10_lang_cond(=<, Ref, Lang, le(lang(Lang,Ref))).
821
+ rdf10_lang_cond(==, Ref, Lang, eq(lang(Lang,Ref))).
822
+ rdf10_lang_cond(>=, Ref, Lang, ge(lang(Lang,Ref))).
823
+ rdf10_lang_cond(>, Ref, Lang, gt(lang(Lang,Ref))).
824
+
825
+ rdf10_type_cond( <, Ref, Type, lt(type(Type,Ref))).
826
+ rdf10_type_cond(=<, Ref, Type, le(type(Type,Ref))).
827
+ rdf10_type_cond(==, Ref, Type, eq(type(Type,Ref))).
828
+ rdf10_type_cond(>=, Ref, Type, ge(type(Type,Ref))).
829
+ rdf10_type_cond( >, Ref, Type, gt(type(Type,Ref))).
830
+
831
+
832
+ %! in_constaint_type(?Type, -SType, ++Val, -Val0)
833
+
834
+ in_constaint_type(Type, SType, Val, Val0) :-
835
+ nonvar(Type), ground(Val),
836
+ !,
837
+ SType = Type,
838
+ in_ground_type(Type, Val, Val0).
839
+ in_constaint_type(Type, SType, Val, Val0) :-
840
+ var(Type), number(Val),
841
+ !,
842
+ ( integer(Val)
843
+ -> rdf_equal(SType, xsd:integer),
844
+ in_ground_type(xsd:integer, Val, Val0)
845
+ ; float(Val)
846
+ -> rdf_equal(SType, xsd:double),
847
+ in_ground_type(xsd:double, Val, Val0)
848
+ ; assertion(fail)
849
+ ).
850
+
851
+
852
+ %! literal_class(+Term, -Class)
853
+ %
854
+ % Classify Term as literal and if possible as lang or typed
855
+ % literal on the basis of the constraints that apply to it.
856
+
857
+ literal_class(Term, Class) :-
858
+ get_attr(Term, rdf11, Conds),
859
+ select(Cond, Conds, Rest),
860
+ lang_condition(Cond),
861
+ !,
862
+ Term = Text@Lang,
863
+ put_attr(Lang, rdf11, [Cond]),
864
+ put_cond(Text, Rest),
865
+ ( var(Text)
866
+ -> true
867
+ ; atom_string(Text2, Text)
868
+ ),
869
+ Class = lang(Lang, Text2).
870
+
871
+ %! attr_unify_hook(+AttributeValue, +Value)
872
+
873
+ attr_unify_hook(Cond, Value) :-
874
+ get_attr(Value, rdf11, Cond2),
875
+ !,
876
+ append(Cond, Cond2, CondJ),
877
+ sort(CondJ, Unique),
878
+ put_cond(Value, Unique).
879
+ attr_unify_hook(Cond, Text^^_Type) :-
880
+ var(Text),
881
+ !,
882
+ put_cond(Text, Cond).
883
+ attr_unify_hook(Cond, Text@Lang) :-
884
+ var(Text), var(Lang),
885
+ !,
886
+ partition(lang_condition, Cond, LangCond, TextCond),
887
+ put_cond(Text, TextCond),
888
+ put_cond(Lang, LangCond).
889
+ attr_unify_hook(Cond, Value) :-
890
+ sort(Cond, Unique),
891
+ propagate_conditions(Unique, Value).
892
+
893
+ propagate_conditions([], _).
894
+ propagate_conditions([H|T], Val) :-
895
+ propagate_condition(H, Val),
896
+ propagate_conditions(T, Val).
897
+
898
+ propagate_condition(value(Comp, Ref, Type), Value) :-
899
+ !,
900
+ ( Value = Plain^^VType
901
+ -> VType = Type
902
+ ; Plain = Value
903
+ ),
904
+ cond_compare(Comp, Ref, Plain).
905
+ propagate_condition(lang_matches(Pattern), Value) :-
906
+ !,
907
+ ( Value = _@Lang
908
+ -> true
909
+ ; Lang = Value
910
+ ),
911
+ rdf_db:lang_matches(Lang, Pattern).
912
+ propagate_condition(Cond, Value) :-
913
+ Cond =.. [Name|Args],
914
+ Constraint =.. [Name,Value|Args],
915
+ rdf_constraint(Constraint, Continuation),
916
+ call(Continuation).
917
+
918
+ cond_compare(>, Ref, Value) :- Value @> Ref.
919
+ cond_compare(>=, Ref, Value) :- Value @>= Ref.
920
+ cond_compare(==, Ref, Value) :- Value == Ref.
921
+ cond_compare(=<, Ref, Value) :- Value @=< Ref.
922
+ cond_compare( <, Ref, Value) :- Value @< Ref.
923
+
924
+
925
+ %! rdf_default_graph(-Graph) is det.
926
+ %! rdf_default_graph(-Old, +New) is det.
927
+ %
928
+ % Query/set the notion of the default graph. The notion of the
929
+ % default graph is local to a thread. Threads created inherit the
930
+ % default graph from their creator. See set_prolog_flag/2.
931
+
932
+ :- create_prolog_flag(rdf_default_graph, default,
933
+ [ type(atom),
934
+ keep(true)
935
+ ]).
936
+
937
+ rdf_default_graph(Graph) :-
938
+ current_prolog_flag(rdf_default_graph, Graph).
939
+ rdf_default_graph(Old, New) :-
940
+ current_prolog_flag(rdf_default_graph, Old),
941
+ ( New == Old
942
+ -> true
943
+ ; set_prolog_flag(rdf_default_graph, New)
944
+ ).
945
+
946
+
947
+ pre_graph(G, _G0) :-
948
+ var(G),
949
+ !.
950
+ pre_graph(G, G) :-
951
+ atom(G),
952
+ !.
953
+ pre_graph(G, _) :-
954
+ type_error(rdf_graph, G).
955
+
956
+ post_graph(G, G0:_) :-
957
+ !,
958
+ G = G0.
959
+ post_graph(G, G).
960
+
961
+
962
+ % left for code calling this directly
963
+
964
+ pre_object(Atom, URI) :-
965
+ pre_object(Atom, URI, _, _).
966
+
967
+ %! pre_object(+APIObject, -DBObject, +APISubject, +APIPredicate)
968
+
969
+ pre_object(Atom, URI, _, _) :-
970
+ atom(Atom),
971
+ \+ boolean(Atom),
972
+ !,
973
+ URI = Atom.
974
+ pre_object(Var, Var1, Subj, Pred) :-
975
+ var(Var),
976
+ !,
977
+ ( literal_condition(Var, Cond)
978
+ -> Var1 = literal(Cond, _)
979
+ ; literal_class(Var, Value)
980
+ -> Var1 = literal(Value)
981
+ ; ( Var == Subj
982
+ -> Var1 = Subj
983
+ ; true
984
+ ),
985
+ ( Var == Pred
986
+ -> Var1 = Pred
987
+ ; true
988
+ )
989
+ ).
990
+ pre_object(Val@Lang, Var1, _, _) :-
991
+ !,
992
+ ( literal_condition(Val, Cond)
993
+ -> Var1 = literal(Cond, lang(Lang, _))
994
+ ; literal_class(Val@Lang, Class)
995
+ -> Var1 = literal(Class)
996
+ ; in_lang_string(Val, Val0),
997
+ Var1 = literal(lang(Lang, Val0))
998
+ ).
999
+ pre_object(Val^^Type, Var1, _, _) :-
1000
+ !,
1001
+ ( literal_condition(Val, Cond)
1002
+ -> Var1 = literal(Cond, type(Type, _))
1003
+ ; in_type(Type, Val, Type0, Val0),
1004
+ ( var(Type0), var(Val0)
1005
+ -> Var1 = literal(_)
1006
+ ; Var1 = literal(type(Type0, Val0))
1007
+ )
1008
+ ).
1009
+ pre_object(Obj, Val0, _, _) :-
1010
+ ground(Obj),
1011
+ !,
1012
+ pre_ground_object(Obj, Val0).
1013
+ pre_object(Obj, _, _, _) :-
1014
+ type_error(rdf_object, Obj).
1015
+
1016
+
1017
+ %! pre_ground_object(+Object, -RDF) is det.
1018
+ %
1019
+ % Convert between a Prolog value and an RDF value for rdf_assert/3
1020
+ % and friends. Auto-conversion:
1021
+ %
1022
+ % - Integer
1023
+ % Converted to Integer^^xsd:integer
1024
+ % - Float
1025
+ % Converted to Float^^xsd:double
1026
+ % - String
1027
+ % Converted to String^^xsd:string
1028
+ % - true
1029
+ % Converted to true^^xsd:boolean
1030
+ % - false
1031
+ % Converted to false^^xsd:boolean
1032
+ % - date(Y,M,D)
1033
+ % Converted to date(Y,M,D)^^xsd:date
1034
+ % - date_time(Y,M,D,HH,MM,SS)
1035
+ % Converted to date_time(Y,M,D,HH,MM,SS)^^xsd:dateTime
1036
+ % - date_time(Y,M,D,HH,MM,SS,TZ)
1037
+ % Converted to date_time(Y,M,D,HH,MM,SS,TZ)^^xsd:dateTime
1038
+ % - month_day(M,D)
1039
+ % Converted to month_day(M,D)^^xsd:gMonthDay
1040
+ % - year_month(Y,M)
1041
+ % Converted to year_month(Y,M)^^xsd:gYearMonth
1042
+ % - time(HH,MM,SS)
1043
+ % Converted to time(HH,MM,SS)^^xsd:time
1044
+ % - Text@Lang
1045
+ % Converted to Text@Lang. Uses canonical (lowercase) lang.
1046
+ % Text is converted into an atom.
1047
+ % - Value^^Type
1048
+ % Typed conversion. The translation of Value depends on
1049
+ % Type:
1050
+ % - Numeric types
1051
+ % - Boolean
1052
+ % - Date types
1053
+ % - Atom
1054
+ % All atoms except for `true` and `false` are considered
1055
+ % URIs.
1056
+
1057
+ :- rdf_meta
1058
+ pre_ground_object(+, o).
1059
+
1060
+ pre_ground_object(Val@Lang, literal(lang(Lang0, Val0))) :-
1061
+ !,
1062
+ downcase_atom(Lang, Lang0),
1063
+ in_lang_string(Val, Val0).
1064
+ pre_ground_object(Val^^Type, literal(type(Type0, Val0))) :-
1065
+ !,
1066
+ in_type(Type, Val, Type0, Val0).
1067
+ pre_ground_object(literal(Lit0), literal(Lit)) :-
1068
+ old_literal(Lit0, Lit),
1069
+ !.
1070
+ % Interpret `false' and `true' as the Boolean values.
1071
+ pre_ground_object(false, literal(type(xsd:boolean, false))) :- !.
1072
+ pre_ground_object(true, literal(type(xsd:boolean, true))) :- !.
1073
+ pre_ground_object(Atom, URI) :-
1074
+ atom(Atom),
1075
+ !,
1076
+ URI = Atom.
1077
+ % Interpret Prolog integer as xsd:integer.
1078
+ pre_ground_object(Int, Object) :-
1079
+ integer(Int),
1080
+ !,
1081
+ rdf_equal(Object, literal(type(xsd:integer, Atom))),
1082
+ atom_number(Atom, Int).
1083
+ % Interpret Prolog floating-point value as xsd:double.
1084
+ pre_ground_object(Float, Object) :-
1085
+ float(Float),
1086
+ !,
1087
+ rdf_equal(Object, literal(type(xsd:double, Atom))),
1088
+ xsd_number_string(Float, String),
1089
+ atom_string(Atom, String).
1090
+ % Interpret SWI string as xsd:string.
1091
+ pre_ground_object(String, Object) :-
1092
+ string(String),
1093
+ !,
1094
+ rdf_equal(Object, literal(type(xsd:string, Atom))),
1095
+ atom_string(Atom, String).
1096
+ % Interpret date(Y,M,D) as xsd:date,
1097
+ % date_time(Y,M,D,HH,MM,SS) as xsd:dateTime,
1098
+ % date_time(Y,M,D,HH,MM,SS,TZ) as xsd:dateTime,
1099
+ % month_day(M,D) as xsd:gMonthDay,
1100
+ % year_month(Y,M) as xsd:gYearMonth, and
1101
+ % time(HH,MM,SS) as xsd:time.
1102
+ pre_ground_object(Term, literal(type(Type, Atom))) :-
1103
+ xsd_date_time_term(Term),
1104
+ !,
1105
+ xsd_time_string(Term, Type, String),
1106
+ atom_string(Atom, String).
1107
+ pre_ground_object(Value, _) :-
1108
+ type_error(rdf_object, Value).
1109
+
1110
+ xsd_date_time_term(date(_,_,_)).
1111
+ xsd_date_time_term(date_time(_,_,_,_,_,_)).
1112
+ xsd_date_time_term(date_time(_,_,_,_,_,_,_)).
1113
+ xsd_date_time_term(month_day(_,_)).
1114
+ xsd_date_time_term(year_month(_,_)).
1115
+ xsd_date_time_term(time(_,_,_)).
1116
+
1117
+ old_literal(Lit0, Lit) :-
1118
+ old_literal(Lit0),
1119
+ !,
1120
+ Lit = Lit0.
1121
+ old_literal(Atom, Lit) :-
1122
+ atom(Atom),
1123
+ rdf_equal(xsd:string, XSDString),
1124
+ Lit = type(XSDString, Atom).
1125
+
1126
+ old_literal(type(Type, Value)) :-
1127
+ atom(Type), atom(Value).
1128
+ old_literal(lang(Lang, Value)) :-
1129
+ atom(Lang), atom(Value).
1130
+
1131
+ in_lang_string(Val, Val0) :-
1132
+ atomic(Val),
1133
+ !,
1134
+ atom_string(Val0, Val).
1135
+ in_lang_string(_, _).
1136
+
1137
+ in_type(Type, Val, Type, Val0) :-
1138
+ nonvar(Type), ground(Val),
1139
+ !,
1140
+ in_ground_type(Type, Val, Val0).
1141
+ in_type(VarType, Val, VarType, Val0) :-
1142
+ ground(Val),
1143
+ \+ catch(xsd_number_string(_, Val), _, fail),
1144
+ !,
1145
+ atom_string(Val0, Val).
1146
+ in_type(_, _, _, _).
1147
+
1148
+ :- rdf_meta
1149
+ in_ground_type(r,?,?),
1150
+ in_date_component(r, +, +, -).
1151
+
1152
+ %! in_ground_type(+Type, +Input, -Lexical:atom) is det.
1153
+ %
1154
+ % Translate the Prolog date Input according to Type into its RDF
1155
+ % lexical form. The lexical form is represented as an atom. In
1156
+ % future versions this is likely to become a string.
1157
+
1158
+ in_ground_type(Type, Input, Lex) :-
1159
+ \+ string(Input),
1160
+ in_ground_type_hook(Type, Input, Lex),
1161
+ !.
1162
+ in_ground_type(IntType, Val, Val0) :-
1163
+ xsd_numerical(IntType, Domain, PrologType),
1164
+ !,
1165
+ in_number(PrologType, Domain, IntType, Val, Val0).
1166
+ in_ground_type(xsd:boolean, Val, Val0) :-
1167
+ !,
1168
+ ( in_boolean(Val, Val0)
1169
+ -> true
1170
+ ; type_error(rdf_boolean, Val)
1171
+ ).
1172
+ in_ground_type(rdf:langString, _Val0, _) :-
1173
+ !,
1174
+ domain_error(rdf_data_type, rdf:langString).
1175
+ in_ground_type(DateTimeType, Val, Val0) :-
1176
+ xsd_date_time_type(DateTimeType),
1177
+ !,
1178
+ in_date_time(DateTimeType, Val, Val0).
1179
+ in_ground_type(rdf:'XMLLiteral', Val, Val0) :-
1180
+ !,
1181
+ in_xml_literal(xml, Val, Val0).
1182
+ in_ground_type(rdf:'HTML', Val, Val0) :-
1183
+ !,
1184
+ in_xml_literal(html, Val, Val0).
1185
+ in_ground_type(_Unknown, Val, Val0) :-
1186
+ atom_string(Val0, Val).
1187
+
1188
+ %! in_date_time(+Type, +Input, -Lexical) is det.
1189
+ %
1190
+ % Accepts either a term as accepted by xsd_time_string/3 or a
1191
+ % valid string for the corresponding XSD type.
1192
+
1193
+ :- rdf_meta
1194
+ in_date_time(r,+,-).
1195
+
1196
+ in_date_time(Type, Text, Text0) :-
1197
+ atom(Text),
1198
+ !,
1199
+ xsd_time_string(_, Type, Text),
1200
+ Text0 = Text.
1201
+ in_date_time(Type, Text, Text0) :-
1202
+ string(Text),
1203
+ !,
1204
+ xsd_time_string(_, Type, Text),
1205
+ atom_string(Text0, Text).
1206
+ in_date_time(xsd:dateTime, Stamp, Text0) :-
1207
+ number(Stamp),
1208
+ !,
1209
+ format_time(atom(Text0), '%FT%T%:z', Stamp).
1210
+ in_date_time(Type, Term, Text0) :-
1211
+ !,
1212
+ xsd_time_string(Term, Type, String),
1213
+ atom_string(Text0, String).
1214
+
1215
+
1216
+ %! in_boolean(?NonCanonical, ?Canonical)
1217
+ %
1218
+ % True when Canonical is the canonical boolean for NonCanonical.
1219
+
1220
+ in_boolean(true, true).
1221
+ in_boolean(false, false).
1222
+ in_boolean("true", true).
1223
+ in_boolean("false", false).
1224
+ in_boolean(1, true).
1225
+ in_boolean(0, false).
1226
+
1227
+ boolean(false).
1228
+ boolean(true).
1229
+
1230
+ %! in_number(+PrologType, +Domain, +XSDType, +Value, -Lexical)
1231
+ %
1232
+ % Lexical is the lexical representation for Value.
1233
+ %
1234
+ % @error type_error(PrologType, Value)
1235
+ % @error domain_error(XSDType, Value)
1236
+
1237
+ in_number(integer, Domain, XSDType, Val, Val0) :-
1238
+ integer(Val),
1239
+ !,
1240
+ check_integer_domain(Domain, XSDType, Val),
1241
+ atom_number(Val0, Val).
1242
+ in_number(integer, Domain, XSDType, Val, Val0) :-
1243
+ atomic(Val),
1244
+ atom_number(Val, Num),
1245
+ integer(Num),
1246
+ !,
1247
+ check_integer_domain(Domain, XSDType, Num),
1248
+ atom_number(Val0, Num).
1249
+ in_number(double, _Domain, _, Val, Val0) :-
1250
+ number(Val),
1251
+ !,
1252
+ ValF is float(Val),
1253
+ xsd_number_string(ValF, ValS),
1254
+ atom_string(Val0, ValS).
1255
+ in_number(double, _Domain, _, Val, Val0) :-
1256
+ atomic(Val),
1257
+ xsd_number_string(Num, Val),
1258
+ ValF is float(Num),
1259
+ !,
1260
+ xsd_number_string(ValF, ValS),
1261
+ atom_string(Val0, ValS).
1262
+ in_number(decimal, _Domain, _, Val, Val0) :-
1263
+ number(Val),
1264
+ !,
1265
+ ValF is float(Val),
1266
+ atom_number(Val0, ValF).
1267
+ in_number(decimal, _Domain, _, Val, Val0) :-
1268
+ atomic(Val),
1269
+ xsd_number_string(Num, Val),
1270
+ ValF is float(Num),
1271
+ !,
1272
+ atom_number(Val0, ValF).
1273
+ in_number(PrologType, _, _, Val, _) :-
1274
+ type_error(PrologType, Val).
1275
+
1276
+ check_integer_domain(PLType, _, Val) :-
1277
+ is_of_type(PLType, Val),
1278
+ !.
1279
+ check_integer_domain(_, XSDType, Val) :-
1280
+ domain_error(XSDType, Val).
1281
+
1282
+ error:has_type(nonpos, T):-
1283
+ integer(T),
1284
+ T =< 0.
1285
+
1286
+ %check_integer_domain(between(Low, High), XSDType, Val) :-
1287
+ % ( between(Low, High, Val)
1288
+ % -> true
1289
+ % ; domain_error(XSDType, Val)
1290
+ % ).
1291
+ %check_integer_domain(integer, _, _).
1292
+
1293
+ %! xsd_numerical(?URI, ?TypeCheck, ?PrologType)
1294
+
1295
+ :- rdf_meta
1296
+ xsd_numerical(r, ?, ?).
1297
+
1298
+ xsd_numerical(xsd:byte, between(-128,127), integer).
1299
+ xsd_numerical(xsd:double, float, double).
1300
+ xsd_numerical(xsd:decimal, float, decimal).
1301
+ xsd_numerical(xsd:float, float, double).
1302
+ xsd_numerical(xsd:int, between(-2147483648,2147483647), integer).
1303
+ xsd_numerical(xsd:integer, integer, integer).
1304
+ xsd_numerical(xsd:long, between(-9223372036854775808,
1305
+ 9223372036854775807), integer).
1306
+ xsd_numerical(xsd:negativeInteger, negative_integer, integer).
1307
+ xsd_numerical(xsd:nonNegativeInteger, nonneg, integer).
1308
+ xsd_numerical(xsd:nonPositiveInteger, nonpos, integer).
1309
+ xsd_numerical(xsd:positiveInteger, positive_integer, integer).
1310
+ xsd_numerical(xsd:short, between(-32768,32767), integer).
1311
+ xsd_numerical(xsd:unsignedByte, between(0,255), integer).
1312
+ xsd_numerical(xsd:unsignedInt, between(0,4294967295), integer).
1313
+ xsd_numerical(xsd:unsignedLong, between(0,18446744073709551615), integer).
1314
+ xsd_numerical(xsd:unsignedShort, between(0,65535), integer).
1315
+
1316
+ %! xsd_date_time_type(?URI)
1317
+ %
1318
+ % True when URI is an XSD date or time type.
1319
+
1320
+ :- rdf_meta
1321
+ xsd_date_time_type(r).
1322
+
1323
+ xsd_date_time_type(xsd:date).
1324
+ xsd_date_time_type(xsd:dateTime).
1325
+ xsd_date_time_type(xsd:gDay).
1326
+ xsd_date_time_type(xsd:gMonth).
1327
+ xsd_date_time_type(xsd:gMonthDay).
1328
+ xsd_date_time_type(xsd:gYear).
1329
+ xsd_date_time_type(xsd:gYearMonth).
1330
+ xsd_date_time_type(xsd:time).
1331
+
1332
+
1333
+ %! in_xml_literal(+Type, +Val, -Val0) is det.
1334
+ %
1335
+ % Translate an XMLLiteral or HTML literal to its canonical textual
1336
+ % representation. Input is either text or a Prolog XML DOM.
1337
+ %
1338
+ % @tbd Deal with partial content?
1339
+
1340
+ in_xml_literal(Type, Val, Val0) :-
1341
+ xml_is_dom(Val),
1342
+ !,
1343
+ write_xml_literal(Type, Val, Val0).
1344
+ in_xml_literal(xml, Val, Val0) :-
1345
+ parse_partial_xml(load_xml, Val, DOM),
1346
+ write_xml_literal(xml, DOM, Val0).
1347
+ in_xml_literal(html, Val, Val0) :-
1348
+ parse_partial_xml(load_html, Val, DOM),
1349
+ write_xml_literal(html, DOM, Val0).
1350
+
1351
+ parse_partial_xml(Parser, Val, DOM) :-
1352
+ setup_call_cleanup(
1353
+ new_memory_file(MF),
1354
+ ( setup_call_cleanup(
1355
+ open_memory_file(MF, write, Out),
1356
+ format(Out, "<xml>~w</xml>", [Val]),
1357
+ close(Out)),
1358
+ setup_call_cleanup(
1359
+ open_memory_file(MF, read, In),
1360
+ call(Parser, stream(In), [element(xml, _, DOM)], []),
1361
+ close(In))
1362
+ ),
1363
+ free_memory_file(MF)).
1364
+
1365
+
1366
+ write_xml_literal(xml, DOM, Text) :-
1367
+ with_output_to(atom(Text),
1368
+ xml_write_canonical(current_output, DOM, [])).
1369
+ write_xml_literal(html, DOM, Text) :-
1370
+ with_output_to(atom(Text),
1371
+ html_write(current_output, DOM,
1372
+ [ header(false),
1373
+ layout(false)
1374
+ ])).
1375
+
1376
+ %! rdf_canonical_literal(++In, -Literal) is det.
1377
+ %
1378
+ % Transform a relaxed literal specification as allowed for
1379
+ % rdf_assert/3 into its canonical form. The following Prolog terms
1380
+ % are translated:
1381
+ %
1382
+ % | **Prolog Term** | **Datatype IRI** |
1383
+ % |:------------------------------|:-----------------|
1384
+ % | float | xsd:double |
1385
+ % | integer | xsd:integer |
1386
+ % | string | xsd:string |
1387
+ % | `true` or `false` | xsd:boolean |
1388
+ % | date(Y,M,D) | xsd:date |
1389
+ % | date_time(Y,M,D,HH,MM,SS) | xsd:dateTime |
1390
+ % | date_time(Y,M,D,HH,MM,SS,TZ) | xsd:dateTime |
1391
+ % | month_day(M,D) | xsd:gMonthDay |
1392
+ % | year_month(Y,M) | xsd:gYearMonth |
1393
+ % | time(HH,MM,SS) | xsd:time |
1394
+ %
1395
+ % For example:
1396
+ %
1397
+ % ```
1398
+ % ?- rdf_canonical_literal(42, X).
1399
+ % X = 42^^'http://www.w3.org/2001/XMLSchema#integer'.
1400
+ % ```
1401
+
1402
+ rdf_canonical_literal(In, Literal) :-
1403
+ ground(In),
1404
+ !,
1405
+ pre_ground_object(In, DBTerm),
1406
+ post_object(Literal, DBTerm).
1407
+ rdf_canonical_literal(In, _) :-
1408
+ must_be(ground, In).
1409
+
1410
+ %! rdf_lexical_form(++Literal, -Lexical:compound) is det.
1411
+ %
1412
+ % True when Lexical is the lexical form for the literal Literal.
1413
+ % Lexical is of one of the forms below. The ntriples serialization
1414
+ % is obtained by transforming String into a proper ntriples string
1415
+ % using double quotes and escaping where needed and turning Type
1416
+ % into a proper IRI reference.
1417
+ %
1418
+ % - String^^Type
1419
+ % - String@Lang
1420
+
1421
+ % For example,
1422
+ %
1423
+ % ==
1424
+ % ?- rdf_lexical_form(2.3^^xsd:double, L).
1425
+ % L = "2.3E0"^^'http://www.w3.org/2001/XMLSchema#double'.
1426
+ % ==
1427
+
1428
+ rdf_lexical_form(Literal, Lexical) :-
1429
+ pre_ground_object(Literal, literal(Lit0)),
1430
+ !,
1431
+ text_of0(Lit0, Lexical).
1432
+ rdf_lexical_form(Literal, _) :-
1433
+ type_error(rdf_literal, Literal).
1434
+
1435
+ text_of0(type(TypeA, LexicalA), LexicalS^^TypeA) :-
1436
+ atom_string(LexicalA, LexicalS).
1437
+ text_of0(lang(LangA, LexicalA), LexicalS@LangA) :-
1438
+ atom_string(LexicalA, LexicalS).
1439
+
1440
+
1441
+ /*******************************
1442
+ * POST PROCESSING *
1443
+ *******************************/
1444
+
1445
+ :- rdf_meta
1446
+ post_object(o,o),
1447
+ out_type(r,-,+).
1448
+
1449
+ post_object(Val, _) :-
1450
+ ground(Val),
1451
+ !. % already specified and matched
1452
+ post_object(URI, URI0) :-
1453
+ atom(URI0),
1454
+ !,
1455
+ URI = URI0.
1456
+ post_object(Val@Lang, literal(lang(Lang, Val0))) :-
1457
+ nonvar(Lang), % lang(Lang,Text) returns var(Lang) if no lang
1458
+ !,
1459
+ atom_string(Val0, Val).
1460
+ post_object(Val^^Type, literal(type(Type, Val0))) :-
1461
+ !,
1462
+ out_type(Type, Val, Val0).
1463
+ post_object(Val^^xsd:string, literal(Plain)) :-
1464
+ !,
1465
+ atomic(Plain),
1466
+ atom_string(Plain, Val).
1467
+ post_object(Val@Lang, literal(_, lang(Lang, Val0))) :-
1468
+ nonvar(Lang),
1469
+ !,
1470
+ atom_string(Val0, Val).
1471
+ post_object(Val^^Type, literal(_, type(Type, Val0))) :-
1472
+ !,
1473
+ out_type(Type, Val, Val0).
1474
+ post_object(Val^^xsd:string, literal(_, Plain)) :-
1475
+ atomic(Plain),
1476
+ atom_string(Plain, Val).
1477
+
1478
+ out_type(xsd:string, Val, Val0) :- % catches unbound type too
1479
+ !,
1480
+ atom_string(Val0, Val).
1481
+ out_type(Type, Val, Val0) :-
1482
+ out_type_hook(Type, Val, Val0),
1483
+ !.
1484
+ out_type(IntType, Val, Val0) :-
1485
+ xsd_numerical(IntType, _Domain, _BasicType),
1486
+ !,
1487
+ xsd_number_string(Val, Val0).
1488
+ out_type(DateTimeType, Val, Val0) :-
1489
+ xsd_date_time_type(DateTimeType),
1490
+ !,
1491
+ out_date_time(DateTimeType, Val, Val0).
1492
+ out_type(xsd:boolean, Val, Val0) :-
1493
+ !,
1494
+ Val = Val0.
1495
+ out_type(rdf:'XMLLiteral', XML, DOM) :-
1496
+ xml_is_dom(DOM),
1497
+ !,
1498
+ with_output_to(string(XML),
1499
+ xml_write(DOM, [header(false)])).
1500
+ out_type(_Unknown, Val, Val0) :-
1501
+ atom_string(Val0, Val).
1502
+
1503
+
1504
+ %! out_date_time(+DateTimeType, -Val, +Val0) is det.
1505
+ %
1506
+ % Translate an XSD lexical form for a date/time related datatype
1507
+ % into the canonical form as defined by xsd_time_string/3.
1508
+
1509
+ out_date_time(Type, Prolog, Lexical) :-
1510
+ catch(xsd_time_string(Prolog, Type, Lexical),
1511
+ error(_,_),
1512
+ invalid_lexical_form_hook(Type, Lexical, Prolog)).
1513
+
1514
+
1515
+ %! invalid_lexical_form_hook(+Type, +Lexical, -Prolog)
1516
+ %
1517
+ % This hook is called if translation of the lexical form to the Prolog
1518
+ % representation fails due to a syntax error. By default it is not
1519
+ % defined, causing such invalid triples to be silently ignored.
1520
+
1521
+
1522
+ /*******************************
1523
+ * ENUMERATION *
1524
+ *******************************/
1525
+
1526
+ %! rdf_term(?Term) is nondet.
1527
+ %
1528
+ % True if Term appears in the RDF database. Term is either an IRI,
1529
+ % literal or blank node and may appear in any position of any
1530
+ % triple. If Term is ground, it is pre-processed as the object
1531
+ % argument of rdf_assert/3 and the predicate is _semidet_.
1532
+
1533
+ rdf_term(N) :-
1534
+ ground(N),
1535
+ !,
1536
+ pre_object(N, N0, _, _),
1537
+ visible_term(N0).
1538
+ rdf_term(N) :-
1539
+ gen_term(N).
1540
+
1541
+ gen_term(N) :-
1542
+ resource(N),
1543
+ visible_term(N).
1544
+ gen_term(O) :- % performs double conversion!
1545
+ rdf_literal(O),
1546
+ (rdf(_,_,O) -> true).
1547
+
1548
+ %! rdf_literal(?Term) is nondet.
1549
+ %
1550
+ % True if Term is a known literal. If Term is ground, it is
1551
+ % pre-processed as the object argument of rdf_assert/3 and the
1552
+ % predicate is _semidet_.
1553
+
1554
+ rdf_literal(Term) :-
1555
+ ground(Term),
1556
+ !,
1557
+ ( boolean(Term)
1558
+ ; \+ atom(Term)
1559
+ ),
1560
+ !,
1561
+ pre_ground_object(Term, Object),
1562
+ (rdf_db:rdf(_,_,Object)->true).
1563
+ rdf_literal(Term) :-
1564
+ pre_object(Term,literal(Lit0), _, _),
1565
+ rdf_db:rdf_current_literal(Lit0),
1566
+ (rdf_db:rdf(_,_,literal(Lit0))->true),
1567
+ post_object(Term, literal(Lit0)).
1568
+
1569
+ %! rdf_bnode(?BNode) is nondet.
1570
+ %
1571
+ % True if BNode is a currently known blank node. The predicate is
1572
+ % _semidet_ if BNode is ground.
1573
+
1574
+ rdf_bnode(BNode) :-
1575
+ atom(BNode),
1576
+ !,
1577
+ current_bnode(BNode).
1578
+ rdf_bnode(BNode) :-
1579
+ rdf_db:rdf_resource(BNode),
1580
+ current_bnode(BNode).
1581
+
1582
+ current_bnode(BNode) :-
1583
+ rdf_is_bnode(BNode),
1584
+ visible_node(BNode). % Assumes BNodes cannot be predicates
1585
+
1586
+ %! rdf_iri(?IRI) is nondet.
1587
+ %
1588
+ % True if IRI is a current IRI. The predicate is _semidet_ if IRI
1589
+ % is ground.
1590
+
1591
+ rdf_iri(IRI) :-
1592
+ atom(IRI),
1593
+ !,
1594
+ \+ rdf_is_bnode(IRI),
1595
+ visible_term(IRI).
1596
+ rdf_iri(IRI) :-
1597
+ resource(IRI),
1598
+ \+ rdf_is_bnode(IRI),
1599
+ visible_term(IRI).
1600
+
1601
+ %! rdf_name(?Name) is nondet.
1602
+ %
1603
+ % True if Name is a current IRI or literal. The predicate is
1604
+ % _semidet_ if Name is ground.
1605
+
1606
+ rdf_name(Name) :-
1607
+ atom(Name), \+ boolean(Name),
1608
+ !,
1609
+ \+ rdf_is_bnode(Name),
1610
+ visible_term(Name).
1611
+ rdf_name(Name) :-
1612
+ ground(Name),
1613
+ !,
1614
+ pre_ground_object(Name, Name0),
1615
+ (rdf_db:rdf(_,_,Name0)->true).
1616
+ rdf_name(Name) :-
1617
+ rdf_iri(Name).
1618
+ rdf_name(Name) :-
1619
+ rdf_literal(Name).
1620
+
1621
+ %! rdf_subject(?S) is nondet.
1622
+ %
1623
+ % True when S is a currently known _subject_, i.e. it appears in
1624
+ % the subject position of some visible triple. The predicate is
1625
+ % _semidet_ if S is ground.
1626
+
1627
+
1628
+ %! rdf_predicate(?P) is nondet.
1629
+ %
1630
+ % True when P is a currently known predicate, i.e. it appears in
1631
+ % the predicate position of some visible triple. The predicate is
1632
+ % _semidet_ if P is ground.
1633
+
1634
+ rdf_predicate(P) :-
1635
+ atom(P),
1636
+ !,
1637
+ (rdf(_,P,_) -> true).
1638
+ rdf_predicate(P) :-
1639
+ rdf_db:rdf_current_predicate(P),
1640
+ (rdf(_,P,_) -> true).
1641
+
1642
+ %! rdf_object(?O) is nondet.
1643
+ %
1644
+ % True when O is a currently known object, i.e. it appears in the
1645
+ % object position of some visible triple. If Term is ground, it is
1646
+ % pre-processed as the object argument of rdf_assert/3 and the
1647
+ % predicate is _semidet_.
1648
+
1649
+ rdf_object(O) :-
1650
+ ground(O),
1651
+ !,
1652
+ ( atom(O), \+ boolean(O)
1653
+ -> (rdf_db:rdf(_,_,O) -> true)
1654
+ ; rdf_literal(O)
1655
+ ).
1656
+ rdf_object(O) :-
1657
+ rdf_db:rdf_resource(O),
1658
+ (rdf_db:rdf(_,_,O) -> true).
1659
+ rdf_object(O) :-
1660
+ rdf_literal(O).
1661
+
1662
+ %! rdf_node(?T) is nondet.
1663
+ %
1664
+ % True when T appears in the subject or object position of a known
1665
+ % triple, i.e., is a node in the RDF graph.
1666
+
1667
+ rdf_node(N) :-
1668
+ var(N),
1669
+ !,
1670
+ gen_node(N).
1671
+ rdf_node(N) :-
1672
+ pre_ground_object(N, N0),
1673
+ visible_node(N0).
1674
+
1675
+ gen_node(N) :-
1676
+ rdf_db:rdf_resource(N),
1677
+ visible_node(N).
1678
+ gen_node(O) :- % performs double conversion!
1679
+ rdf_literal(O),
1680
+ (rdf(_,_,O) -> true).
1681
+
1682
+ %! resource(?R)
1683
+ %
1684
+ % True if R is a node that is not a literal. Note that RDF-DB does
1685
+ % not necessarily include predicates in the set of resources. Also
1686
+ % note that the resource may not really exist or be visible.
1687
+
1688
+ resource(R) :-
1689
+ var(R),
1690
+ !,
1691
+ gen_resource(R).
1692
+ resource(R) :-
1693
+ rdf_db:rdf_resource(R),
1694
+ !.
1695
+ resource(R) :-
1696
+ rdf_db:rdf_current_predicate(R),
1697
+ !.
1698
+
1699
+ gen_resource(R) :-
1700
+ rdf_db:rdf_resource(R).
1701
+ gen_resource(R) :-
1702
+ rdf_db:rdf_current_predicate(R),
1703
+ \+ rdf_db:rdf_resource(R).
1704
+
1705
+ visible_node(Term) :-
1706
+ atom(Term),
1707
+ !,
1708
+ ( rdf_db:rdf(Term,_,_)
1709
+ ; rdf_db:rdf(_,_,Term)
1710
+ ),
1711
+ !.
1712
+ visible_node(Term) :-
1713
+ rdf_db:rdf(_,_,Term).
1714
+
1715
+ visible_term(Term) :-
1716
+ atom(Term),
1717
+ !,
1718
+ ( rdf_db:rdf(Term,_,_)
1719
+ ; rdf_db:rdf(_,Term,_)
1720
+ ; rdf_db:rdf(_,_,Term)
1721
+ ),
1722
+ !.
1723
+ visible_term(Term) :-
1724
+ rdf_db:rdf(_,_,Term).
1725
+
1726
+ %! rdf_create_bnode(--BNode)
1727
+ %
1728
+ % Create a new BNode. A blank node is an atom starting with
1729
+ % =|_:|=. Blank nodes generated by this predicate are of the form
1730
+ % =|_:genid|= followed by a unique integer.
1731
+
1732
+ rdf_create_bnode(BNode) :-
1733
+ var(BNode),
1734
+ !,
1735
+ rdf_db:rdf_bnode(BNode).
1736
+ rdf_create_bnode(BNode) :-
1737
+ uninstantiation_error(BNode).
1738
+
1739
+
1740
+ /*******************************
1741
+ * TYPE CHECKING *
1742
+ *******************************/
1743
+
1744
+ %! rdf_is_iri(@IRI) is semidet.
1745
+ %
1746
+ % True if IRI is an RDF IRI term.
1747
+ %
1748
+ % For performance reasons, this does not check for compliance to
1749
+ % the syntax defined in [[RFC
1750
+ % 3987][http://www.ietf.org/rfc/rfc3987.txt]]. This checks
1751
+ % whether the term is (1) an atom and (2) not a blank node
1752
+ % identifier.
1753
+ %
1754
+ % Success of this goal does not imply that the IRI is present in
1755
+ % the database (see rdf_iri/1 for that).
1756
+
1757
+ rdf_is_iri(IRI) :-
1758
+ atom(IRI),
1759
+ \+ rdf_is_bnode(IRI).
1760
+
1761
+ %! rdf_is_bnode(@Term) is semidet.
1762
+ %
1763
+ % True if Term is an RDF blank node identifier.
1764
+ %
1765
+ % A blank node is represented by an atom that starts with
1766
+ % =|_:|=.
1767
+ %
1768
+ % Success of this goal does not imply that the blank node is
1769
+ % present in the database (see rdf_bnode/1 for that).
1770
+ %
1771
+ % For backwards compatibility, atoms that are represented with
1772
+ % an atom that starts with =|__|= are also considered to be a
1773
+ % blank node.
1774
+
1775
+
1776
+ %! rdf_is_literal(@Term) is semidet.
1777
+ %
1778
+ % True if Term is an RDF literal term.
1779
+ %
1780
+ % An RDF literal term is of the form `String@LanguageTag` or
1781
+ % `Value^^Datatype`.
1782
+ %
1783
+ % Success of this goal does not imply that the literal is
1784
+ % well-formed or that it is present in the database (see
1785
+ % rdf_literal/1 for that).
1786
+
1787
+ rdf_is_literal(Literal) :-
1788
+ literal_form(Literal),
1789
+ !,
1790
+ ground(Literal).
1791
+
1792
+ literal_form(_@_).
1793
+ literal_form(_^^_).
1794
+
1795
+
1796
+ %! rdf_is_name(@Term) is semidet.
1797
+ %
1798
+ % True if Term is an RDF Name, i.e., an IRI or literal.
1799
+ %
1800
+ % Success of this goal does not imply that the name is
1801
+ % well-formed or that it is present in the database (see
1802
+ % rdf_name/1 for that).
1803
+
1804
+ rdf_is_name(T) :- rdf_is_iri(T), !.
1805
+ rdf_is_name(T) :- rdf_is_literal(T).
1806
+
1807
+
1808
+ %! rdf_is_object(@Term) is semidet.
1809
+ %
1810
+ % True if Term can appear in the object position of a triple.
1811
+ %
1812
+ % Success of this goal does not imply that the object term in
1813
+ % well-formed or that it is present in the database (see
1814
+ % rdf_object/1 for that).
1815
+ %
1816
+ % Since any RDF term can appear in the object position, this is
1817
+ % equivalent to rdf_is_term/1.
1818
+
1819
+ rdf_is_object(T) :- rdf_is_subject(T), !.
1820
+ rdf_is_object(T) :- rdf_is_literal(T).
1821
+
1822
+
1823
+ %! rdf_is_predicate(@Term) is semidet.
1824
+ %
1825
+ % True if Term can appear in the predicate position of a triple.
1826
+ %
1827
+ % Success of this goal does not imply that the predicate term is
1828
+ % present in the database (see rdf_predicate/1 for that).
1829
+ %
1830
+ % Since only IRIs can appear in the predicate position, this is
1831
+ % equivalent to rdf_is_iri/1.
1832
+
1833
+ rdf_is_predicate(T) :- rdf_is_iri(T).
1834
+
1835
+
1836
+ %! rdf_is_subject(@Term) is semidet.
1837
+ %
1838
+ % True if Term can appear in the subject position of a triple.
1839
+ %
1840
+ % Only blank nodes and IRIs can appear in the subject position.
1841
+ %
1842
+ % Success of this goal does not imply that the subject term is
1843
+ % present in the database (see rdf_subject/1 for that).
1844
+ %
1845
+ % Since blank nodes are represented by atoms that start with
1846
+ % `_:` and an IRIs are atoms as well, this is equivalent to
1847
+ % atom(Term).
1848
+
1849
+ rdf_is_subject(T) :- atom(T).
1850
+
1851
+ %! rdf_is_term(@Term) is semidet.
1852
+ %
1853
+ % True if Term can be used as an RDF term, i.e., if Term is
1854
+ % either an IRI, a blank node or an RDF literal.
1855
+ %
1856
+ % Success of this goal does not imply that the RDF term is
1857
+ % present in the database (see rdf_term/1 for that).
1858
+
1859
+ rdf_is_term(N) :- rdf_is_subject(N), !.
1860
+ rdf_is_term(N) :- rdf_is_literal(N).
1861
+
1862
+
1863
+ /*******************************
1864
+ * COLLECTIONS *
1865
+ *******************************/
1866
+
1867
+ %! rdf_list(?RDFTerm) is semidet.
1868
+ %
1869
+ % True if RDFTerm is a proper RDF list. This implies that every
1870
+ % node in the list has an `rdf:first` and `rdf:rest` property and
1871
+ % the list ends in `rdf:nil`.
1872
+ %
1873
+ % If RDFTerm is unbound, RDFTerm is bound to each _maximal_ RDF
1874
+ % list. An RDF list is _maximal_ if there is no triple rdf(_,
1875
+ % rdf:rest, RDFList).
1876
+
1877
+ rdf_list(L) :-
1878
+ var(L),
1879
+ !,
1880
+ rdf_has(L, rdf:first, _),
1881
+ \+ rdf_has(_, rdf:rest, L),
1882
+ rdf_list_g(L).
1883
+ rdf_list(L) :-
1884
+ rdf_list_g(L),
1885
+ !.
1886
+
1887
+ :- rdf_meta
1888
+ rdf_list_g(r).
1889
+
1890
+ rdf_list_g(rdf:nil) :- !.
1891
+ rdf_list_g(L) :-
1892
+ once(rdf_has(L, rdf:first, _)),
1893
+ rdf_has(L, rdf:rest, Rest),
1894
+ ( rdf_equal(rdf:nil, Rest)
1895
+ -> true
1896
+ ; rdf_list_g(Rest)
1897
+ ).
1898
+
1899
+
1900
+ %! rdf_list(+RDFList, -PrologList) is det.
1901
+ %
1902
+ % True when PrologList represents the rdf:first objects for all
1903
+ % cells in RDFList. Note that this can be non-deterministic if
1904
+ % cells have multiple rdf:first or rdf:rest triples.
1905
+
1906
+ rdf_list(RDFList, Prolog) :-
1907
+ rdf_is_subject(RDFList),
1908
+ !,
1909
+ rdf_list_to_prolog(RDFList, Prolog).
1910
+ rdf_list(RDFList, _Prolog) :-
1911
+ type_error(rdf_subject, RDFList).
1912
+
1913
+ :- rdf_meta
1914
+ rdf_list_to_prolog(r,-).
1915
+
1916
+ rdf_list_to_prolog(rdf:nil, Prolog) :-
1917
+ !,
1918
+ Prolog = [].
1919
+ rdf_list_to_prolog(RDF, [H|T2]) :-
1920
+ ( rdf_has(RDF, rdf:first, H0),
1921
+ rdf_has(RDF, rdf:rest, T1)
1922
+ *-> H = H0,
1923
+ rdf_list_to_prolog(T1, T2)
1924
+ ; type_error(rdf_list, RDF)
1925
+ ).
1926
+
1927
+
1928
+ %! rdf_length(+RDFList, -Length:nonneg) is nondet.
1929
+ %
1930
+ % True when Length is the number of cells in RDFList. Note that a
1931
+ % list cell may have multiple rdf:rest triples, which makes this
1932
+ % predicate non-deterministic. This predicate does not check
1933
+ % whether the list cells have associated values (rdf:first). The
1934
+ % list must end in rdf:nil.
1935
+
1936
+ rdf_length(RDFList, Len) :-
1937
+ rdf_is_subject(RDFList),
1938
+ !,
1939
+ rdf_length(RDFList, 0, Len).
1940
+
1941
+ :- rdf_meta
1942
+ rdf_length(r,+,-).
1943
+
1944
+ rdf_length(rdf:nil, Len, Len) :- !.
1945
+ rdf_length(RDF, Len0, Len) :-
1946
+ ( rdf_has(RDF, rdf:rest, T)
1947
+ *-> Len1 is Len0+1,
1948
+ rdf_length(T, Len1, Len)
1949
+ ; type_error(rdf_list, RDF)
1950
+ ).
1951
+
1952
+
1953
+ %! rdf_member(?Member, +RDFList) is nondet.
1954
+ %
1955
+ % True when Member is a member of RDFList
1956
+
1957
+ rdf_member(M, L) :-
1958
+ ground(M),
1959
+ !,
1960
+ ( rdf_member2(M, L)
1961
+ -> true
1962
+ ).
1963
+ rdf_member(M, L) :-
1964
+ rdf_member2(M, L).
1965
+
1966
+ rdf_member2(M, L) :-
1967
+ rdf_has(L, rdf:first, M).
1968
+ rdf_member2(M, L) :-
1969
+ rdf_has(L, rdf:rest, L1),
1970
+ rdf_member2(M, L1).
1971
+
1972
+
1973
+ %! rdf_nextto(?X, ?Y) is nondet.
1974
+ %! rdf_nextto(?X, ?Y, ?RdfList) is nondet.
1975
+ %
1976
+ % True if Y directly follows X in RdfList.
1977
+
1978
+ rdf_nextto(X, Y) :-
1979
+ distinct(X-Y, rdf_nextto(X, Y, _)).
1980
+
1981
+
1982
+ rdf_nextto(X, Y, L) :-
1983
+ var(X), ground(Y),
1984
+ !,
1985
+ rdf_nextto(Y, X, L).
1986
+ rdf_nextto(X, Y, L) :-
1987
+ rdf_has(L, rdf:first, X),
1988
+ rdf_has(L, rdf:rest, T),
1989
+ rdf_has(T, rdf:first, Y).
1990
+
1991
+
1992
+ %! rdf_nth0(?Index, +RDFList, ?X) is nondet.
1993
+ %! rdf_nth1(?Index, +RDFList, ?X) is nondet.
1994
+ %
1995
+ % True when X is the Index-th element (0-based or 1-based) of
1996
+ % RDFList. This predicate is deterministic if Index is given and
1997
+ % the list has no multiple rdf:first or rdf:rest values.
1998
+
1999
+ rdf_nth0(I, L, X) :-
2000
+ rdf_nth(0, I, L, X).
2001
+
2002
+ rdf_nth1(I, L, X) :-
2003
+ rdf_nth(1, I, L, X).
2004
+
2005
+ rdf_nth(Offset, I, L, X) :-
2006
+ rdf_is_subject(L),
2007
+ !,
2008
+ ( var(I)
2009
+ -> true
2010
+ ; must_be(nonneg, I)
2011
+ ),
2012
+ rdf_nth_(I, Offset, L, X).
2013
+ rdf_nth(_, _, L, _) :-
2014
+ type_error(rdf_subject, L).
2015
+
2016
+ rdf_nth_(I, I0, L, X) :-
2017
+ ( I0 == I
2018
+ -> !
2019
+ ; I0 = I
2020
+ ),
2021
+ rdf_has(L, rdf:first, X).
2022
+ rdf_nth_(I, I0, L, X) :-
2023
+ rdf_has(L, rdf:rest, T),
2024
+ I1 is I0+1,
2025
+ rdf_nth_(I, I1, T, X).
2026
+
2027
+
2028
+ %! rdf_last(+RDFList, -Last) is det.
2029
+ %
2030
+ % True when Last is the last element of RDFList. Note that if the
2031
+ % last cell has multiple rdf:first triples, this predicate becomes
2032
+ % nondet.
2033
+
2034
+ rdf_last(L, Last) :-
2035
+ rdf_is_subject(L),
2036
+ !,
2037
+ rdf_has(L, rdf:rest, T),
2038
+ ( rdf_equal(T, rdf:nil)
2039
+ -> rdf_has(L, rdf:first, Last)
2040
+ ; rdf_last(T, Last)
2041
+ ).
2042
+ rdf_last(L, _) :-
2043
+ type_error(rdf_subject, L).
2044
+
2045
+
2046
+ %! rdf_estimate_complexity(?S, ?P, ?O, -Estimate) is det.
2047
+
2048
+ rdf_estimate_complexity(S, P, O, Estimate) :-
2049
+ pre_object(O,O0,S,P),
2050
+ rdf_db:rdf_estimate_complexity(S,P,O0,Estimate).
2051
+
2052
+
2053
+ %! rdf_assert_list(+PrologList, ?RDFList) is det.
2054
+ %! rdf_assert_list(+PrologList, ?RDFList, +Graph) is det.
2055
+ %
2056
+ % Create an RDF list from the given Prolog List. PrologList must
2057
+ % be a proper Prolog list and all members of the list must be
2058
+ % acceptable as object for rdf_assert/3. If RDFList is unbound and
2059
+ % PrologList is not empty, rdf_create_bnode/1 is used to create
2060
+ % RDFList.
2061
+
2062
+ rdf_assert_list(Prolog, RDF) :-
2063
+ rdf_default_graph(G),
2064
+ rdf_assert_list(Prolog, RDF, G).
2065
+
2066
+ rdf_assert_list(Prolog, RDF, G) :-
2067
+ must_be(list, Prolog),
2068
+ rdf_transaction(rdf_assert_list_(Prolog, RDF, G)).
2069
+
2070
+ rdf_assert_list_([], Nil, _) :-
2071
+ rdf_equal(rdf:nil, Nil).
2072
+ rdf_assert_list_([H|T], L2, G) :-
2073
+ (var(L2) -> rdf_create_bnode(L2) ; true),
2074
+ rdf_assert(L2, rdf:type, rdf:'List', G),
2075
+ rdf_assert(L2, rdf:first, H, G),
2076
+ ( T == []
2077
+ -> rdf_assert(L2, rdf:rest, rdf:nil, G)
2078
+ ; rdf_create_bnode(T2),
2079
+ rdf_assert(L2, rdf:rest, T2, G),
2080
+ rdf_assert_list_(T, T2, G)
2081
+ ).
2082
+
2083
+
2084
+ %! rdf_retract_list(+RDFList) is det.
2085
+ %
2086
+ % Retract the rdf:first, rdf:rest and rdf:type=rdf:'List' triples
2087
+ % from all nodes reachable through rdf:rest. Note that other
2088
+ % triples that exist on the nodes are left untouched.
2089
+
2090
+ rdf_retract_list(L) :-
2091
+ rdf_is_subject(L),
2092
+ !,
2093
+ rdf_transaction(rdf_retract_list_(L)).
2094
+ rdf_retract_list(L) :-
2095
+ type_error(rdf_subject, L).
2096
+
2097
+ :- rdf_meta
2098
+ rdf_retract_list_(r).
2099
+
2100
+ rdf_retract_list_(rdf:nil) :- !.
2101
+ rdf_retract_list_(L) :-
2102
+ rdf_retractall(L, rdf:first, _),
2103
+ forall(rdf_has(L, rdf:rest, L1),
2104
+ rdf_retract_list_(L1)),
2105
+ rdf_retractall(L, rdf:rest, _),
2106
+ rdf_retractall(L, rdf:type, rdf:'List').