Index: trunk/extensions/SemanticMediaWiki/RELEASE-NOTES |
— | — | @@ -8,6 +8,11 @@ |
9 | 9 | Semantic MediaWiki 1.7.1 is currently in beta-quality and is not recommended for use in |
10 | 10 | production until the actual release. |
11 | 11 | |
| 12 | +* Added basic support for OpenLink Virtuoso RDF database. In addition to |
| 13 | + $smwgDefaultStore = 'SMWSparqlStore', users should set |
| 14 | + $smwgSparqlDatabase = 'SMWSparqlDatabaseVirtuoso' and use Virtuoso's SPARQL |
| 15 | + endpoint at ./sparql/ for query and update alike. for further remarks and known |
| 16 | + limitations, see the file ./includes/sparql/SMW_SparqlDatabaseVirtuoso.php . |
12 | 17 | * Added ability to sort dates as dates in tables generated by SMW (bug 25768). |
13 | 18 | * When there are only invalid query conditions, query answering is stopped (bug 33177). |
14 | 19 | * Fixed display of nearby values on Special:SearchByProperty (bug 34178). |
Index: trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabaseVirtuoso.php |
— | — | @@ -0,0 +1,157 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Virtuoso specific adjustments for SMWSparqlDatabase |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup SMWSparql |
| 8 | + * |
| 9 | + * @author Markus Krötzsch |
| 10 | + */ |
| 11 | + |
| 12 | + |
| 13 | +/** |
| 14 | + * Specific modifications of the SPARQL database implementation for Virtuoso. |
| 15 | + * In particular, Virtuoso does not support SPARQL Update but only the non-standard |
| 16 | + * SPARUL protocol that requires different syntax for update queries. |
| 17 | + * If future versions of Virtuoso support SPARQL Update, the standard SPARQL |
| 18 | + * database connector should work properly. |
| 19 | + * |
| 20 | + * Virtuoso uses the SPARQL query endpoint for updates as well. So both |
| 21 | + * $smwgSparqlUpdateEndpoint and $smwgSparqlQueryEndpoint should be something |
| 22 | + * like 'http://localhost:8890/sparql/'. $smwgSparqlDataEndpoint should be |
| 23 | + * left empty. |
| 24 | + * |
| 25 | + * A graph is always needed, i.e., $smwgSparqlDefaultGraph must be set to some |
| 26 | + * graph name (URI). |
| 27 | + * |
| 28 | + * Known limitations: |
| 29 | + * (might be fixed in recent Virtuoso versions, please let us know) |
| 30 | + * |
| 31 | + * - Data endpoint not tested: $smwgSparqlDataEndpoint should be left empty |
| 32 | + * - Numerical datatypes are not supported properly, and Virtuoso |
| 33 | + * will miss query results when query conditions require number values. |
| 34 | + * This also affects Type:Date properties since the use numerical values for |
| 35 | + * querying. |
| 36 | + * - Some edit (insert) queries fail for unknown reasons, probably related to |
| 37 | + * unusual/complex input data (e.g., using special characters in strings); |
| 38 | + * errors will occur when trying to store such values on a page. |
| 39 | + * - Virtuoso stumbles over XSD dates with negative years, even if they have |
| 40 | + * only four digits as per ISO. Trying to store such data will cause errors. |
| 41 | + * |
| 42 | + * @since 1.7.1 |
| 43 | + * @ingroup SMWSparql |
| 44 | + * |
| 45 | + * @author Markus Krötzsch |
| 46 | + */ |
| 47 | +class SMWSparqlDatabaseVirtuoso extends SMWSparqlDatabase { |
| 48 | + |
| 49 | + /** |
| 50 | + * DELETE wrapper. |
| 51 | + * The function declares the standard namespaces wiki, swivt, rdf, owl, |
| 52 | + * rdfs, property, xsd, so these do not have to be included in |
| 53 | + * $extraNamespaces. |
| 54 | + * |
| 55 | + * @param $deletePattern string CONSTRUCT pattern of tripples to delete |
| 56 | + * @param $where string condition for data to delete |
| 57 | + * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 58 | + * @return boolean stating whether the operations succeeded |
| 59 | + */ |
| 60 | + public function delete( $deletePattern, $where, $extraNamespaces = array() ) { |
| 61 | + $sparql = self::getPrefixString( $extraNamespaces ) . "DELETE" . |
| 62 | + ( ( $this->m_defaultGraph !== '' )? " FROM <{$this->m_defaultGraph}> " : '' ) . |
| 63 | + "{ $deletePattern } WHERE { $where }"; |
| 64 | + return $this->doUpdate( $sparql ); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * INSERT DELETE wrapper. |
| 69 | + * The function declares the standard namespaces wiki, swivt, rdf, owl, |
| 70 | + * rdfs, property, xsd, so these do not have to be included in |
| 71 | + * $extraNamespaces. |
| 72 | + * |
| 73 | + * @param $insertPattern string CONSTRUCT pattern of tripples to insert |
| 74 | + * @param $deletePattern string CONSTRUCT pattern of tripples to delete |
| 75 | + * @param $where string condition for data to delete |
| 76 | + * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 77 | + * @return boolean stating whether the operations succeeded |
| 78 | + */ |
| 79 | + public function insertDelete( $insertPattern, $deletePattern, $where, $extraNamespaces = array() ) { |
| 80 | + $sparql = self::getPrefixString( $extraNamespaces ) . "MODIFY" . |
| 81 | + ( ( $this->m_defaultGraph !== '' )? " GRAPH <{$this->m_defaultGraph}> " : '' ) . |
| 82 | + "DELETE { $deletePattern } INSERT { $insertPattern } WHERE { $where }"; |
| 83 | + return $this->doUpdate( $sparql ); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * INSERT DATA wrapper. |
| 88 | + * The function declares the standard namespaces wiki, swivt, rdf, owl, |
| 89 | + * rdfs, property, xsd, so these do not have to be included in |
| 90 | + * $extraNamespaces. |
| 91 | + * |
| 92 | + * @param $triples string of triples to insert |
| 93 | + * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 94 | + * @return boolean stating whether the operations succeeded |
| 95 | + */ |
| 96 | + public function insertData( $triples, $extraNamespaces = array() ) { |
| 97 | + if ( $this->m_dataEndpoint !== '' ) { |
| 98 | + $turtle = self::getPrefixString( $extraNamespaces, false ) . $triples; |
| 99 | + return $this->doHttpPost( $turtle ); |
| 100 | + } else { |
| 101 | + $sparql = self::getPrefixString( $extraNamespaces, true ) . |
| 102 | + "INSERT DATA " . |
| 103 | + ( ( $this->m_defaultGraph !== '' )? "INTO GRAPH <{$this->m_defaultGraph}> " : '' ) . |
| 104 | + "{ $triples }"; |
| 105 | + return $this->doUpdate( $sparql ); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * DELETE DATA wrapper. |
| 111 | + * The function declares the standard namespaces wiki, swivt, rdf, owl, |
| 112 | + * rdfs, property, xsd, so these do not have to be included in |
| 113 | + * $extraNamespaces. |
| 114 | + * |
| 115 | + * @param $triples string of triples to delete |
| 116 | + * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 117 | + * @return boolean stating whether the operations succeeded |
| 118 | + */ |
| 119 | + public function deleteData( $triples, $extraNamespaces = array() ) { |
| 120 | + $sparql = self::getPrefixString( $extraNamespaces ) . |
| 121 | + "DELETE DATA " . |
| 122 | + ( ( $this->m_defaultGraph !== '' )? "FROM GRAPH <{$this->m_defaultGraph}> " : '' ) . |
| 123 | + "{ $triples }"; |
| 124 | + return $this->doUpdate( $sparql ); |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | + /** |
| 129 | + * Execute a SPARQL update and return a boolean to indicate if the |
| 130 | + * operations was successful. |
| 131 | + * |
| 132 | + * Virtuoso expects SPARQL updates to be posted using the "query" |
| 133 | + * parameter (rather than "update"). |
| 134 | + * |
| 135 | + * @param $sparql string with the complete SPARQL update query (INSERT or DELETE) |
| 136 | + * @return boolean |
| 137 | + */ |
| 138 | + public function doUpdate( $sparql ) { |
| 139 | + if ( $this->m_updateEndpoint === '' ) { |
| 140 | + throw new SMWSparqlDatabaseError( SMWSparqlDatabaseError::ERROR_NOSERVICE, $sparql, 'not specified' ); |
| 141 | + } |
| 142 | + curl_setopt( $this->m_curlhandle, CURLOPT_URL, $this->m_updateEndpoint ); |
| 143 | + curl_setopt( $this->m_curlhandle, CURLOPT_POST, true ); |
| 144 | + $parameterString = "query=" . urlencode( $sparql ); |
| 145 | + curl_setopt( $this->m_curlhandle, CURLOPT_POSTFIELDS, $parameterString ); |
| 146 | + |
| 147 | + curl_exec( $this->m_curlhandle ); |
| 148 | + |
| 149 | + if ( curl_errno( $this->m_curlhandle ) == 0 ) { |
| 150 | + return true; |
| 151 | + } else { |
| 152 | + $this->throwSparqlErrors( $this->m_updateEndpoint, $sparql ); |
| 153 | + return false; |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | +} |
| 158 | + |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabaseVirtuoso.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 159 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -293,6 +293,7 @@ |
294 | 294 | |
295 | 295 | $wgAutoloadClasses['SMWSparqlDatabase'] = $smwgIP . 'includes/sparql/SMW_SparqlDatabase.php'; |
296 | 296 | $wgAutoloadClasses['SMWSparqlDatabase4Store'] = $smwgIP . 'includes/sparql/SMW_SparqlDatabase4Store.php'; |
| 297 | + $wgAutoloadClasses['SMWSparqlDatabaseVirtuoso'] = $smwgIP . 'includes/sparql/SMW_SparqlDatabaseVirtuoso.php'; |
297 | 298 | $wgAutoloadClasses['SMWSparqlDatabaseError'] = $smwgIP . 'includes/sparql/SMW_SparqlDatabase.php'; |
298 | 299 | $wgAutoloadClasses['SMWSparqlResultWrapper'] = $smwgIP . 'includes/sparql/SMW_SparqlResultWrapper.php'; |
299 | 300 | $wgAutoloadClasses['SMWSparqlResultParser'] = $smwgIP . 'includes/sparql/SMW_SparqlResultParser.php'; |