TQLFeatures » History » Version 2
Paula Gearon, 01/06/2008 06:46 AM
| 1 | 2 | Paula Gearon | |
|---|---|---|---|
| 2 | h1. TQL Language Features |
||
| 3 | |||
| 4 | 1 | Paula Gearon | TQL requires a new set of features for insert-select queries: |
| 5 | |||
| 6 | 2 | Paula Gearon | * Unbound parameters should be allowed in the select clause of these queries, permitting the insertion of new blank nodes. |
| 7 | * The select clause should permit a multiple of 3 items, and not just the current 3 items, permitting multiple insertions for each row of the returned result. |
||
| 8 | 1 | Paula Gearon | |
| 9 | The second of these features is the more difficult, as it needs to intercept the code path which is performing insertions of raw data into the indexes. It could be done either by mapping each insertion into a set of triples to be inserted, or else the insertions could be repeated, with a different set each time. |
||
| 10 | |||
| 11 | The purpose of these features is to allow for queries like the following: |
||
| 12 | 2 | Paula Gearon | <pre> |
| 13 | 1 | Paula Gearon | insert select |
| 14 | $item <ns:length> $blank |
||
| 15 | $blank <ns:units> <ns:inches> |
||
| 16 | $blank <ns:value> $length |
||
| 17 | from <rmi://localhost/server1#model> |
||
| 18 | where $item <ns2:inchLengh> $length |
||
| 19 | into <rmi://localhost/server1#model>; |
||
| 20 | 2 | Paula Gearon | </pre> |
| 21 | 1 | Paula Gearon | This query cannot be performed as a set of 3 separate insertions, as it requires the same blank node in each statement. The only option at the moment is to build up the insertions manually from the client end, but this has several problems: |
| 22 | |||
| 23 | 2 | Paula Gearon | * Will require a new insertion for every record returned from the select clause. |
| 24 | * Must be performed on a client, and not done in the server. |
||
| 25 | * Cannot be included as a part of the rules engine. |
||
| 26 | 1 | Paula Gearon | |
| 27 | The problem in the rules engine is the most important, as this type of statement is required to perform rules on n-ary predicates. The rules themselves never use iTQL to be parsed, but the equivalent query objects are still constructed. |
||
| 28 | |||
| 29 | As an example, the following rule: |
||
| 30 | 2 | Paula Gearon | <pre> |
| 31 | 1 | Paula Gearon | element(ID, X1, Y1, X2, Y2) :- linguistic_element(ID, X1, Y1, X2, Y2). |
| 32 | 2 | Paula Gearon | </pre> |
| 33 | 1 | Paula Gearon | Will be mapped to: |
| 34 | 2 | Paula Gearon | <pre> |
| 35 | 1 | Paula Gearon | insert |
| 36 | select |
||
| 37 | $id <pred:element> $a |
||
| 38 | $a <e:1> $x1 |
||
| 39 | $a <e:2> $y1 |
||
| 40 | $a <e:3> $x2 |
||
| 41 | $a <e:4> $y2 |
||
| 42 | from <rmi://localhost/server1#model> |
||
| 43 | where |
||
| 44 | $id <pred:linguistic_element> $b and |
||
| 45 | $b <e:1> $x1 and |
||
| 46 | $b <e:2> $y1 and |
||
| 47 | $b <e:3> $x2 and |
||
| 48 | $b <e:4> $y2 |
||
| 49 | into <rmi://localhost/server1#model>; |
||
| 50 | 2 | Paula Gearon | </pre> |
| 51 | 1 | Paula Gearon | |
| 52 | 2 | Paula Gearon | ~original page by Paul Gearon on Nov 01, 2006~ |
| 53 | 1 | Paula Gearon | |
| 54 | ---- |
||
| 55 | Select clauses are tested for a width of 3 at: |
||
| 56 | |||
| 57 | resolver/java/org/mulgara/resolver/ModifyModelOperation.java:164 |
||
| 58 | |||
| 59 | ---- |
||
| 60 | The width is tested again at line: |
||
| 61 | |||
| 62 | resolver/java/org/mulgara/resolver/ModifyModelOperation.java : 204 |
||
| 63 | |||
| 64 | The statements to be inserted are instantiated at line 205: |
||
| 65 | 2 | Paula Gearon | <pre> |
| 66 | <code class="java"> |
||
| 67 | statements = new [[TuplesWrapperStatements]]( |
||
| 68 | new [[LocalizedTuples]](systemResolver, answer), |
||
| 69 | varsr0, varsr1, varsr2); |
||
| 70 | </code></pre> |
||
| 71 | 1 | Paula Gearon | It may be possible to wrap this in a loop, with the vars offsets added to an incrementing loop variable. The trick here is identifying unbound vars and ensuring that they are replaced with a new blank node. |
| 72 | |||
| 73 | ---- |
||
| 74 | 2 | Paula Gearon | The 2 parameter LocalizedTuples constructor presumes a non-persistent localization. This is incorrect for blank nodes. So if the answer object contains an unbound variable, then the different constructor should be used. |
| 75 | 1 | Paula Gearon | |
| 76 | 2 | Paula Gearon | However, if the loop around the TuplesWrapperStatements constructor is to be followed, then blank nodes will need to be stored from one instance to the next. This is possible, but would require storage of the complete list, which may be larger than memory. |
| 77 | 1 | Paula Gearon | |
| 78 | The other option is to create a new Tuples Wrapper which is aware of the N*3 columns, and shifts sideways with each call to next(). This can then allocate new blank nodes during iteration, and drop them every Nth call to next(). |