SWI-Prolog Semantic Web Library

Abstract

The semweb library provides a Prolog library based on foreign-language extensions for storing and manipulating RDF triples. It can handle quite large sets of triples only limited by available memory. One million triples requires about 80MB memory, so a fully equiped 32-bit machine can handle about 25 million triples. A 64-bit machine with 32Gb memory (just a few thousand euros in june 2009) can handle up to 150 million triples.

Prerequisites

This library depends on the RDF parser library which in turn depends on the XML parser provided by the sgml package.

Further info

This library defines the semantic web infrastructure for SWI-Prolog. The library is documented in semweb.pdf or the equivalent semweb.html. If your installation does not include this file, please visit http://www.swi-prolog.org/packages/

Staying up-to-date

This library is under active development. The recent version can be accessed from the GIT repository under the directory pl/packages/semweb. See http://www.swi-prolog.org/git.html for details on the central GIT repository and instructions for browsing the repository online.

Prolog files

rdf11.pl  -- RDF 1.1 APIShow source
rdf_bnode/1True if BNode is a currently known blank node.Source
rdf_canonical_literal/2Transform a relaxed literal specification as allowed for rdf_assert/3 into its canonical form.Source
rdf_compare/3True if the RDF terms Left and Right are ordered according to the comparison operator Diff.Source
rdf_create_bnode/1Create a new BNode.Source
rdf_estimate_complexity/4Source
rdf_iri/1True if IRI is a current IRI.Source
rdf_is_bnode/1True if Term is an RDF blank node identifier.Source
rdf_is_iri/1True if IRI is an RDF IRI term.Source
rdf_is_literal/1True if Term is an RDF literal term.Source
rdf_is_name/1True if Term is an RDF Name, i.e., an IRI or literal.Source
rdf_is_object/1True if Term can appear in the object position of a triple.Source
rdf_is_predicate/1True if Term can appear in the predicate position of a triple.Source
rdf_is_subject/1True if Term can appear in the subject position of a triple.Source
rdf_is_term/1True if Term can be used as an RDF term, i.e., if Term is either an IRI, a blank node or an RDF literal.Source
rdf_last/2True when Last is the last element of RDFList.Source
rdf_length/2True when Length is the number of cells in RDFList.Source
rdf_lexical_form/2True when Lexical is the lexical form for the literal Literal.Source
rdf_list/1True if RDFTerm is a proper RDF list.Source
rdf_list/2True when PrologList represents the rdf:first objects for all cells in RDFList.Source
rdf_literal/1True if Term is a known literal.Source
rdf_member/2True when Member is a member of RDFList.Source
rdf_name/1True if Name is a current IRI or literal.Source
rdf_node/1True when T appears in the subject or object position of a known triple, i.e., is a node in the RDF graph.Source
rdf_object/1True when O is a currently known object, i.e.Source
rdf_predicate/1True when P is a currently known predicate, i.e.Source
rdf_retract_list/1Retract the rdf:first, rdf:rest and rdf:type=rdf:'List' triples from all nodes reachable through rdf:rest.Source
rdf_subject/1True when S is a currently known subject, i.e.Source
rdf_term/1True if Term appears in the RDF database.Source
rdf/3True if an RDF triple <S,P,O> exists, optionally in the graph G.
rdf_assert/3Assert a new triple.
rdf_assert_list/2Create an RDF list from the given Prolog List.
rdf_default_graph/1Query/set the notion of the default graph.
rdf_has/3Similar to rdf/3 and rdf/4, but P matches all predicates that are defined as an rdfs:subPropertyOf of P.
rdf_nextto/2True if Y directly follows X in RdfList.
rdf_nth0/3True when X is the Index-th element (0-based or 1-based) of RDFList.
rdf_reachable/3True when O can be reached from S using the transitive closure of P.
rdf_retractall/3Remove all matching triples from the database.
rdf_update/4Replaces one of the three fields on the matching triples depending on Action:.
{}/1Formulate constraints on RDF terms, notably literals.
rdf_cache.pl  -- Cache RDF triplesShow source
rdf_cache_file/3File is the cache file for URL.Source
rdf_set_cache_options/1Change the cache policy.Source
rdf_db.pl  -- Core RDF databaseShow source
lang_equal/2True if two RFC language specifiers denote the same language.Source
lang_matches/2True if Lang matches Pattern.Source
ns/2Dynamic and multifile predicate that maintains the registered namespace aliases.Source
rdf/3Elementary query for triples.Source
rdf/4As rdf/3 but in addition query the graph to which the triple belongs.Source
rdf_active_transaction/1True if Id is the identifier of a transaction in the context of which this call is executed.Source
rdf_assert/3Assert a new triple into the database.Source
rdf_assert/4As rdf_assert/3, adding the predicate to the indicated named graph.Source
rdf_atom_md5/3Computes the MD5 hash from Text, which is an atom, string or list of character codes.Source
rdf_bnode/1Generate a unique anonymous identifier for a subject.Source
rdf_compare/3Compare two object terms.Source
rdf_create_graph/1Create an RDF graph without triples.Source
rdf_current_literal/1True when Literal is a currently known literal.Source
rdf_current_ns/2Source
rdf_current_predicate/1True when Predicate is a currently known predicate.Source
rdf_current_prefix/2Query predefined prefixes and prefixes defined with rdf_register_prefix/2 and local prefixes defined with rdf_prefix/2.Source
rdf_current_snapshot/1True when Term is a currently known snapshot.Source
rdf_debug/1Set debugging to Level.Source
rdf_delete_literal_map/2Delete Key and all associated values from the map.Source
rdf_delete_literal_map/3Delete the association between Key and Value from the map.Source
rdf_delete_snapshot/1Delete a snapshot as obtained from rdf_snapshot/1.Source
rdf_destroy_literal_map/1Destroy a literal map.Source
rdf_equal/2Simple equality test to exploit goal-expansion.Source
rdf_estimate_complexity/4Return the number of alternatives as indicated by the database internal hashed indexing.Source
rdf_file_type/2True if Format is the format belonging to the given file extension.Source
rdf_find_literal_map/3Unify ValueList with an ordered set of values associated to all keys from KeyList.Source
rdf_gc/0Run the RDF-DB garbage collector until no garbage is left and all tables are fully optimized.Source
rdf_generation/1True when Generation is the current generation of the database.Source
rdf_global_id/2Convert between Prefix:Local and full IRI (an atom).Source
rdf_global_object/2Same as rdf_global_id/2, but intended for dealing with the object part of a triple, in particular the type for typed literals.Source
rdf_global_term/2Performs rdf_global_id/2 on predixed IRIs and rdf_global_object/2 on RDF literals, by recursively analysing the term.Source
rdf_graph/1True when Graph is an existing graph.Source
rdf_graph_property/2True when Property is a property of Graph.Source
rdf_has/3Succeeds if the triple rdf(Subject, Predicate, Object) is true exploiting the rdfs:subPropertyOf predicate as well as inverse predicates declared using rdf_set_predicate/2 with the inverse_of property.Source
rdf_has/4Same as rdf_has/3, but RealPredicate is unified to the actual predicate that makes this relation true.Source
rdf_insert_literal_map/3Add a relation between Key and Value to the map.Source
rdf_insert_literal_map/4As rdf_insert_literal_map/3.Source
rdf_is_bnode/1Tests if a resource is a blank node (i.e.Source
rdf_is_literal/1True if Term is an RDF literal object.Source
rdf_is_resource/1True if Term is an RDF resource.Source
rdf_keys_in_literal_map/3Realises various queries on the key-set:.Source
rdf_literal_value/2True when value is the appropriate Prolog representation of Literal in the RDF value space.Source
rdf_load/1Same as rdf_load(FileOrList, []).Source
rdf_load/2Load RDF data.Source
rdf_load_db/1Load triples from a file created using rdf_save_db/2.Source
rdf_load_stream/3Load RDF data from Stream.Source
rdf_make/0Reload all loaded files that have been modified since the last time they were loaded.Source
rdf_match_label/3True if Label matches Pattern according to How.Source
rdf_md5/2True when MD5 is the MD5 hash for all triples in graph.Source
rdf_member_property/2Deal with the rdf:_1, ... properties.Source
rdf_meta/1This directive defines the argument types of the named predicates, which will force compile time namespace expansion for these predicates.Source
rdf_monitor/2Call Goal if specified actions occur on the database.Source
rdf_new_literal_map/1Create a new literal map, returning an opaque handle.Source
rdf_node/1Generate a unique blank node identifier for a subject.Source
rdf_predicate_property/2Query properties of a defined predicate.Source
rdf_prefix/2Register a local prefix.Source
rdf_reachable/3Is true if Object can be reached from Subject following the transitive predicate Predicate or a sub-property thereof, while repecting the symetric(true) or inverse_of(P2) properties.Source
rdf_reachable/5Same as rdf_reachable/3, but in addition, MaxD limits the number of edges expanded and D is unified with the `distance' between Subject and Object.Source
rdf_reset_db/0Remove all triples from the RDF database and reset all its statistics.Source
rdf_reset_literal_map/1Delete all content from the literal map.Source
rdf_resource/1True when Resource is a resource used as a subject or object in a triple.Source
rdf_retractall/3Remove all matching triples from the database.Source
rdf_retractall/4As rdf_retractall/3, also matching Graph.Source
rdf_save/1Same as rdf_save(Out, []).Source
rdf_save/2Write RDF data as RDF/XML.Source
rdf_save_footer/1Finish XML generation and write the document footer.Source
rdf_save_header/2Save XML document header, doctype and open the RDF environment.Source
rdf_save_subject/3Save the triples associated to Subject to Out.Source
rdf_set/1Set properties of the RDF store.Source
rdf_set_graph/2Set properties of Graph.Source
rdf_set_predicate/2Define a property of the predicate.Source
rdf_snapshot/1Take a snapshot of the current state of the RDF store.Source
rdf_source/1True if Source is a loaded source.Source
rdf_source/2True if named Graph is loaded from SourceURL.Source
rdf_source_location/2True when triples for Subject are loaded from Location.Source
rdf_split_url/3Split/join a URL.Source
rdf_statistics/1Obtain statistics on the RDF database.Source
rdf_statistics_literal_map/2Query some statistics of the map.Source
rdf_subject/1True if Resource appears as a subject.Source
rdf_transaction/1Same as rdf_transaction(Goal, user, []).Source
rdf_transaction/2Same as rdf_transaction(Goal, Id, []).Source
rdf_transaction/3Run Goal in an RDF transaction.Source
rdf_unload/1Identify the graph loaded from Source and use rdf_unload_graph/1 to erase this graph.Source
rdf_unload_graph/1Remove Graph from the RDF store.Source
rdf_update/4Replaces one of the three fields on the matching triples depending on Action:.Source
rdf_update/5As rdf_update/4 but allows for specifying the graph.Source
rdf_update_duplicates/0Update the duplicate administration of the RDF store.Source
rdf_update_duplicates/0Update the duplicate administration.Source
rdf_url_namespace/2Namespace is the namespace of URL.Source
rdf_version/1True when Version is the numerical version-id of this library.Source
rdf_warm_indexes/0Warm all indexes.Source
rdf_warm_indexes/1Create the named indexes.Source
rdf_graph_prefixes/2List is a sorted list of prefixes (namepaces) in Graph.
rdf_register_ns/2Register an RDF prefix.
rdf_register_prefix/2Register Prefix as an abbreviation for URI.
rdf_save_db/1Save triples into File in a quick-to-load binary format.
rdf_http_plugin.pl  -- RDF HTTP PluginShow source
rdf_open_hook/8Load hook implementation for HTTP(S) URLs.Source
rdf_content_type/3Quality values are intended to be used in accordance with RFC 2616.Source
rdf_library.pl  -- RDF Library ManagerShow source
rdf_attach_library/1Attach manifest from Source.Source
rdf_current_manifest/1True if URL is the URL of a currently loaded manifest file.Source
rdf_library_index/2Query the content of the library.Source
rdf_library_source/2True of Source is the URL that is part of the given library Id.Source
rdf_list_library/0Prints known RDF library identifiers to current output.Source
rdf_list_library/1Print library dependency tree to the terminal.
rdf_load_library/1Load ontologies from the library.
rdf_litindex.pl  -- Search literalsShow source
rdf_delete_literal_index/1Fully delete a literal index.Source
rdf_literal_index/2True when Index is a literal map containing the index of Type.Source
rdf_set_literal_index_option/1Set options for the literal package.Source
rdf_stopgap_token/1True when Token is a stopgap token.Source
rdf_token_expansions/2Determine which extensions of a token contribute to finding literals.Source
rdf_tokenize_literal/2Tokenize a literal.Source
rdf_find_literal/2Find literals in the RDF database matching Spec.
rdf_ntriples.pl  -- Process files in the RDF N-Triples formatShow source
rdf_file_type/2Bind the ntriples reader to files with the extensions nt, ntriples and nquads.Source
rdf_load_stream/3Plugin rule that supports loading the ntriples and nquads formats.Source
rdf_process_ntriples/3Call-back interface, compatible with the other triple readers.Source
read_nquad/2Read the next quad from Stream as Quad.Source
read_ntriple/2Read the next triple from Stream as Triple.Source
read_ntuple/2Read the next triple or quad from Stream as Tuple.Source
rdf_read_ntriples/3True when Triples/Quads is a list of triples/quads from Input.
rdf_persistency.pl  -- RDF persistency pluginShow source
property_of_graph/2Extend rdf_graph_property/2 with new properties.Source
rdf_attach_db/2Start persistent operations using Directory as place to store files.Source
rdf_current_db/1True if Dir is the current RDF persistent database.Source
rdf_db_to_file/2Translate between database encoding (often an file or URL) and the name we store in the directory.Source
rdf_detach_db/0Detach from the current database.Source
rdf_flush_journals/1Flush dirty journals.Source
rdf_journal_file/2True if File the name of the existing journal file for Graph.Source
rdf_persistency/2Specify whether a database is persistent.Source
rdf_persistency_property/1True when Property is a property of the current persistent database.Source
rdf_snapshot_file/2True if File the name of the existing snapshot file for Graph.Source
rdf_turtle_write.pl  -- Turtle - Terse RDF Triple Language writerShow source
rdf_save_canonical_trig/2Save triples in a canonical format.Source
rdf_save_canonical_turtle/2Save triples in a canonical format.Source
rdf_save_ntriples/2Save RDF using ntriples format.Source
rdf_save_trig/2Save multiple RDF graphs into a TriG file.Source
rdf_save_turtle/2Save an RDF graph as Turtle.Source
rdf_zlib_plugin.pl  -- RDF compressed-data pluginShow source
rdfs.pl  -- RDFS handlingShow source
rdfs_class_property/2Enumerate the properties in the domain of Class.Source
rdfs_find/5Search all classes below Domain for a literal property with that matches String.Source
rdfs_individual_of/2Generate resources belonging to a class or classes a resource belongs to.Source
rdfs_label/2Convert between class and label.Source
rdfs_label/3Resource has Label in Lang.Source
rdfs_list_to_prolog_list/2Convert ann RDFS list (result from parseType=Collection) into a Prolog list of elements.Source
rdfs_member/2As Prolog member on sets.Source
rdfs_subclass_of/2Generate sub/super classes.Source
rdfs_subproperty_of/2Query the property hierarchy.Source
rdfs_assert_list/2Create an RDF list from the given Resources.
rdfs_ns_label/2Present label with namespace indication.
sparql_client.pl  -- SPARQL client libraryShow source
sparql_query/3Execute a SPARQL query on an HTTP SPARQL endpoint.Source
sparql_read_json_result/2The returned Result term is of the format:.Source
sparql_read_xml_result/2Specs from http://www.w3.org/TR/rdf-sparql-XMLres/.Source
sparql_set_server/1Set sparql server default options.Source
turtle.pl  -- Turtle: Terse RDF Triple LanguageShow source
rdf_load_stream/3(Turtle clauses).Source
rdf_load_turtle/3Source
rdf_process_turtle/3Streaming Turtle parser.Source
rdf_read_turtle/3Read a stream or file into a set of triples or quadruples (if faced with TRiG input) of the format.Source