This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
docs:userman [2017/12/04 16:12] kkutt [SPARQL queries] |
docs:userman [2022/03/23 16:59] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Loki Manual - User manual ====== | ||
+ | ===== Editing ===== | ||
+ | ==== Defining Semantic data ==== | ||
+ | There are three main methods of semantic annotations used in Semantic MediaWiki that are supported in Loki: | ||
+ | * categories - a simple form of annotation that allows users to classify pages. To state that article (Wiki page) belongs to the category '' | ||
+ | < | ||
+ | * relations - there is a possibility to describe relationships between two Wiki pages. For example there is a relation '' | ||
+ | < | ||
+ | * attributes - allows to specify relationships of Wiki pages to things that are not Wiki pages. For example, one can state that Wiki page '' | ||
+ | < | ||
+ | It is possible to assign one value to multiple relations or attributes in one annotation, thus: | ||
+ | <code smw> | ||
+ | inhabited by [[inhabited by: | ||
+ | The other functionality allows users to decide, how an annotation should be displayed on the page. It is done by defining an lternative text for the annotation using the pipe symbol (|). If no alternative text is specified, the annotation value (default text) is isplayed. If the alternative text is a single space, no value is displayed. For example, code: | ||
+ | <code smw> | ||
+ | by about [[population: | ||
+ | will be displayed as: | ||
+ | |||
+ | Warsaw is located in [[located in:: | ||
+ | [[page created: | ||
+ | |||
+ | |||
+ | All attributes are displayed as plain text, relations as links to the related page and categories as links to the selected category' | ||
+ | |||
+ | ==== Special pages ==== | ||
+ | Special pages are pages containing metadata informations, | ||
+ | |||
+ | * [[special: | ||
+ | * [[special: | ||
+ | * [[special: | ||
+ | |||
+ | Namespaces for these pages are: for categories - '' | ||
+ | |||
+ | Each property (including categories) can be a subproperty of another property of the same type (eg. a relation cannot be a subproperty of an attribute). This is set on the subproperty' | ||
+ | * for categories: | ||
+ | <code smw> | ||
+ | Category is a subcategory of [[category: | ||
+ | </ | ||
+ | * for relations: | ||
+ | <code smw> | ||
+ | Relation is a subrelation of [[subrelation of:: | ||
+ | </ | ||
+ | * for attributes: | ||
+ | <code smw> | ||
+ | Attribute is a subattribute of [[subattribute of: | ||
+ | </ | ||
+ | * for compatibility with SMW syntax, relations and attributes can use the construction '' | ||
+ | <code smw> | ||
+ | Property is a [[subproperty of:: | ||
+ | </ | ||
+ | |||
+ | ==== Prolog in DokuWiki==== | ||
+ | The simplest way to use Prolog in DokuWiki is to place code between ''< | ||
+ | < | ||
+ | woman(kate). | ||
+ | woman(alice). | ||
+ | woman(anna). | ||
+ | man(john). | ||
+ | man(tom). | ||
+ | </ | ||
+ | Result of given example: | ||
+ | <pl goal=" | ||
+ | woman(kate). | ||
+ | woman(alice). | ||
+ | woman(anna). | ||
+ | man(john). | ||
+ | man(tom). | ||
+ | </pl> | ||
+ | |||
+ | It is important to remember that adding '' | ||
+ | |||
+ | There are three ways to deliver Prolog code: | ||
+ | * As a code placed between tags ''< | ||
+ | * As a DokuWiki file with code ''< | ||
+ | * As url to external file with Prolog code ''< | ||
+ | |||
+ | ===== Searching interfaces ===== | ||
+ | ==== Ask queries ==== | ||
+ | Loki supporst almost full functionality for ask queries known from SMW. Ask queries allow to define pages search conditions and display results. Each query contain list of arguments seperated with vertical line ('' | ||
+ | < | ||
+ | This is conjunction of conditions. To use alternative, | ||
+ | < | ||
+ | Each condition determines the value of property which searched page must contain. Using empty strings for values is allowed. | ||
+ | |||
+ | Conditions can contain alternative values: | ||
+ | < | ||
+ | which is equivalent to: | ||
+ | < | ||
+ | |||
+ | Value of the condition can be sub-query: | ||
+ | < | ||
+ | Each sub-query can contain unlimited amount of sub-queries. | ||
+ | |||
+ | There is special kind of queries in Loki - property chains. Properity chains can be used to obtain simpler notation. For example : | ||
+ | < | ||
+ | can be replaced by: | ||
+ | < | ||
+ | |||
+ | Other query arguments are connected with displaying results. Optional arguments can consist of two types of data: columns to be displayed and additional options. | ||
+ | First group contains names preceded by a question mark. Example: | ||
+ | < | ||
+ | {{#ask: [[category: | ||
+ | | ?located in }} | ||
+ | </ | ||
+ | There is possibility to specify collumn names. | ||
+ | < | ||
+ | | ?located in=Localisation}}</ | ||
+ | | ||
+ | For categories, a specific category name can be selected to single out pages belonging to the given category. If the page belongs to the selected category, an ”X” sign will be put in the appropriate field. Example: | ||
+ | < | ||
+ | {{#ask: [[category: | ||
+ | | ? | ||
+ | | ? | ||
+ | Result of this example: | ||
+ | {{#ask: [[category: | ||
+ | | ? | ||
+ | | ? | ||
+ | |||
+ | The other kind of optional arguments of Ask queries are additional options. Loki supports most of the options used in Semantic MediaWiki. Those options are displayed in table below: | ||
+ | |||
+ | ^ Name ^ Allowed values | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |||
+ | Correct values for '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | ===== Semantic Web ===== | ||
+ | ==== SPARQL queries ==== | ||
+ | Loki supports a limited version of SPARQL. SELECT, ASK and DESCRIBE queries are supported. Full wiki semantic data is always used as datasource. Datatypes are not supported - every literal is a string. Full documentation of SPARQL language is avaliable for example on W3 website (http:// | ||
+ | |||
+ | SPARQL queries consist of: | ||
+ | * PREFIX list ('' | ||
+ | * Query type - At this moment SELECT, ASK and DESCRIBE is avaliable | ||
+ | * List of variables (or constants). For SELECT query it will be selection of columns. For DESCRIBE - list of pages that will be described . | ||
+ | * Search conditions. In this part there is possible to insert OPTIONAL block (not obligatory conditions) or FILTER element (additional conditions) | ||
+ | * additional options: ORDER BY, LIMIT, OFFSET. | ||
+ | |||
+ | FILTER list supported in Loki: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | === SELECT queries === | ||
+ | The result of a SELECT query is displayed as an HTML table. | ||
+ | |||
+ | Example SELECT query: | ||
+ | < | ||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | SELECT ?title ?genre ?author | ||
+ | WHERE | ||
+ | { | ||
+ | ?book wiki:genre ?genre. | ||
+ | ?book wiki:title ?title. | ||
+ | ?book wiki:author ?author. | ||
+ | | ||
+ | } | ||
+ | ORDER BY INC(?title) | ||
+ | LIMIT 5 | ||
+ | </pl> | ||
+ | </ | ||
+ | |||
+ | This query will return table containing title, author and genre of all books which genre is different than handbook. Only 5 results sorted alphabetically : | ||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | SELECT ?title ?genre ?author | ||
+ | WHERE | ||
+ | { | ||
+ | ?book wiki:genre ?genre. | ||
+ | ?book wiki:title ?title. | ||
+ | ?book wiki:author ?author. | ||
+ | | ||
+ | } | ||
+ | ORDER BY INC(?title) | ||
+ | LIMIT 5 | ||
+ | </pl> | ||
+ | |||
+ | === ASK queries === | ||
+ | |||
+ | ASK queries determine whether a result exists. It returns either "'' | ||
+ | |||
+ | <code plwiki> | ||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | ASK { | ||
+ | ?book wiki:genre ?genre. | ||
+ | FILTER ( ? | ||
+ | } | ||
+ | </pl> | ||
+ | </ | ||
+ | |||
+ | This query will return the answer to the question: "Are there any books which genre isn't horror?" | ||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | ASK { | ||
+ | ?book wiki:genre ?genre. | ||
+ | FILTER ( ? | ||
+ | } | ||
+ | </pl> | ||
+ | |||
+ | Example query 2: | ||
+ | < | ||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | ASK { | ||
+ | ?book wiki:genre ?genre. | ||
+ | FILTER ( ? | ||
+ | } | ||
+ | </pl> | ||
+ | |||
+ | OR the same query with the use of direct URI | ||
+ | |||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | ASK { | ||
+ | ?book wiki:genre wiki: | ||
+ | } | ||
+ | </pl> | ||
+ | |||
+ | </ | ||
+ | |||
+ | "Are there any books which genre is thriller?" | ||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | ASK { | ||
+ | ?book wiki:genre ?genre. | ||
+ | FILTER ( ? | ||
+ | } | ||
+ | </pl> | ||
+ | |||
+ | === DESCRIBE queries === | ||
+ | DESCRIBE queries return all semantic informations about pages complying with the query criteria, written in TURTLE (http:// | ||
+ | |||
+ | < | ||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | DESCRIBE ? | ||
+ | WHERE { | ||
+ | ?aktor a " | ||
+ | | ||
+ | ?film a " | ||
+ | wiki: | ||
+ | wiki: | ||
+ | wiki: | ||
+ | | ||
+ | } | ||
+ | </pl> | ||
+ | </ | ||
+ | Query returns actors who plays major role in musicals Metro-Goldwyn-Mayer in years 1959 - 1954. | ||
+ | |||
+ | <pl format=" | ||
+ | PREFIX wiki: <> | ||
+ | DESCRIBE ? | ||
+ | WHERE { | ||
+ | ?aktor a " | ||
+ | | ||
+ | ?film a " | ||
+ | wiki: | ||
+ | wiki: | ||
+ | wiki: | ||
+ | | ||
+ | } | ||
+ | </pl> | ||
+ | ==== Export to RDF ==== | ||
+ | Basic assumption of Loki is ability to storage and process semantic knowledge. For this reason this is very important to allow transfering knowledge from one system to another. For this purpose Semantic Web standards such as RDF, OWL or SPARQL were created. Every Loki page can be exported to a RDF/XML file. It can bo done by opening the page in the '' | ||
+ | |||
+ | The generated RDF/XML file consists of three main parts. The first part contains description of the exported page. The second part contains optional related pages data. This data includes descriptions of pages related to the exported page (determined by the wiki_relation predicate). The number of levels of related pages to be exported (default one - only the selected page is exported) is set by the PlWiki '' | ||
+ | ===== Debug functions ===== | ||
+ | Debugging is a very useful function for user. It can help in the analysis of errors and solving problems. Loki supports debugging Prolog code. | ||
+ | === STDERR redirection === | ||
+ | Loki allows redirection of the standard error stream to display or save messages which are genereted by the SWI-Prolog engine. It is possible by using '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | Example use: | ||
+ | < | ||
+ | |||
+ | Example how it look like on the wiki page : | ||
+ | < | ||
+ | ERROR: / | ||
+ | ERROR: / | ||
+ | ERROR: / | ||
+ | ERROR: / | ||
+ | ERROR: / | ||
+ | ERROR: / | ||
+ | ERROR: Prolog initialisation failed: ERROR: ignore/1: Undefined procedure: invalid_goal/ | ||
+ | |||
+ | === Tracing predicates === | ||
+ | |||
+ | PlWiki uses the non-interactive version of Prolog trace predicate to display debug information on the wiki page. It can be done by using the Prolog tag ”trace” attribute, with a comma separated list of predicate names as its value. Example use: | ||
+ | < | ||
+ | Result of this example on the wikipage: | ||
+ | < | ||
+ | T Call: (6) woman(_G624) | ||
+ | T Exit: (6) woman(kate) | ||
+ | kate | ||
+ | T Redo: (6) woman(_G624) | ||
+ | T Exit: (6) woman(alice) | ||
+ | alice | ||
+ | T Redo: (6) woman(_G624) | ||
+ | T Exit: (6) woman(anna) | ||
+ | anna | ||
+ | </ |