public function diffItOWLAxioms() { //a store is not needed here $store = null; $propLangFilter = Options::getOption('stringPredicateWithForeignlanguages'); $graphURI = Options::getOption('graphURI'); $annotationGraphURI = Options::getOption('annotationGraphURI'); foreach ($propLangFilter as $one) { $this->predicateFilterList[] = $one; } Timer::start('LiveUpdateDestination::diffItOWLAxioms::TripleDiff'); $tripleDiff = new TripleDiff($this->uri, $this->language, $this->predicateFilterList, $this->objectFilterList, $this->predicateObjectFilterList, $store); $filterForNotAnnotatedTriples = $tripleDiff->createFilter($this->predicateFilterList, $this->objectFilterList, $this->predicateObjectFilterList); Timer::stop('LiveUpdateDestination::diffItOWLAxioms::TripleDiff'); Timer::start('LiveUpdateDestination::diffItOWLAxioms::generationOfSPARULqueries'); //get a list of all active extractors Timer::start('LiveUpdateDestination::diffItOWLAxioms::extractorFilter'); $extractedByPattern = RDFtriple::URI(DBM_ORIGIN)->toSPARULPattern($this->storespecific); $subjectpattern = $this->uri->toSPARULPattern($this->storespecific); $extractorFilter = ""; $extTerms = array(); foreach ($this->activeExtractors as $one) { $u = new URI($one); $extPattern = $u->toSPARULPattern($this->storespecific); $extTerms[] = ' ?extractor = ' . $extPattern . ' '; } foreach ($this->purgeExtractors as $one) { $u = new URI($one); $extPattern = $u->toSPARULPattern($this->storespecific); $extTerms[] = ' ?extractor = ' . $extPattern . ' '; } $extractorFilter = 'FILTER ( ' . TripleDiff::assembleTerms($extTerms, '||') . ') . '; //delete triples from all active extractor $deleteSPARUL = array(); $deleteSPARUL['delete_from_all_active_extractors'] = 'DELETE FROM <' . $graphURI . '> { ' . $subjectpattern . ' ?p ?o } WHERE { GRAPH <' . $annotationGraphURI . '> { ?axiom <' . OWL_SUBJECT . '> ' . $subjectpattern . ' . ?axiom <' . OWL_PREDICATE . '> ?p . ?axiom <' . OWL_OBJECT . '> ?o . ?axiom ' . $extractedByPattern . ' ?extractor . ' . $extractorFilter . ' } }'; //removed : // '.$subjectpattern.' ?p ?o //**************************** //delete the corresponding annotations $deleteSPARUL['delete_corresponding_annotations'] = 'DELETE FROM <' . $annotationGraphURI . '> { ?axiom ?axp ?axo . } WHERE { ?axiom <' . OWL_SUBJECT . '> ' . $subjectpattern . ' . ?axiom ' . $extractedByPattern . ' ?extractor . ' . $extractorFilter . ' ?axiom ?axp ?axo . }'; //echo $deleteSPARUL['delete_corresponding_annotations']; /* * taking out: ?axiom <'.OWL_PREDICATE.'> ?p . ?axiom <'.OWL_OBJECT.'> ?o . */ Timer::stop('LiveUpdateDestination::diffItOWLAxioms::extractorFilter'); /*OPTIMIZATIONS * ?axiom ?axp ?axo . maybe could be combined with q1 above * best to ask Joerg Unbehauen who knows SPARUL or OpenLink * */ //*********************** //TODO go to infobox extractor and //add an annotation to all subject/rating objects to which subject they belong //and then delete them also /* *********************** * This became obsolete //delete all triples that do not have an annotation //this is consistent as they will be recreated with annotations //all triples to be kept should be annotated beforehand $deleteSPARUL[] = 'DELETE FROM <' . $graphURI . '> { '.$subjectpattern.' ?p ?o } WHERE { '.$subjectpattern.' ?p ?o . OPTIONAL { ?axiom <'.OWL_SUBJECT.'> '.$subjectpattern.' . } FILTER (!bound($axiom)). }'; // OPTIONAL { '$subjectpattern.' ?p2 ?o2 . FILTER (isLiter) } */ //*********************** //delete all triples with the current subject //according to the filters //do not delete special properties see below //Timer::start('LiveUpdateDestination::diffItOWLAxioms::notAnnotated'); $notAnnotated = 'DELETE FROM <' . $graphURI . '> { ' . $subjectpattern . ' ?p ?o } WHERE { GRAPH <' . $graphURI . '> { ' . $subjectpattern . ' ?p ?o . FILTER (' . $filterForNotAnnotatedTriples . '). } GRAPH <' . $annotationGraphURI . '> { OPTIONAL { ?a <' . OWL_SUBJECT . '> ' . $subjectpattern . '. } FILTER (!bound(?a)). } }'; //echo $notAnnotated;die; $deleteSPARUL['delete_with_subject_not_static'] = $notAnnotated; //Timer::stop('LiveUpdateDestination::diffItOWLAxioms::notAnnotated'); //*********************** //delete all triples with the current subject //where the special properties with string object //from other language version are given, which should stay //Timer::start('LiveUpdateDestination::diffItOWLAxioms::propLangSPARULfilter'); $propTerms = array(); foreach ($propLangFilter as $one) { $u = new URI($one); $predicatePattern = $u->toSPARULPattern($this->storespecific); $propTerms[] = ' ?p = ' . $predicatePattern . ' '; } $propLangSPARULfilter = TripleDiff::assembleTerms($propTerms, '||'); $deleteEnglishLanguage = 'DELETE FROM <' . $graphURI . '> { ' . $subjectpattern . ' ?p ?o } WHERE { ' . $subjectpattern . ' ?p ?o . FILTER (' . $propLangSPARULfilter . ' && (isLiteral(?o)) && (lang (?o) = \'' . $this->language . '\' ) ). }'; /* echo $deleteEnglishLanguage;die; */ $deleteSPARUL['delete_english'] = $deleteEnglishLanguage; //Timer::stop('LiveUpdateDestination::diffItOWLAxioms::propLangSPARULfilter'); //write the new triples Timer::start('LiveUpdateDestination::diffItOWLAxioms::insertSPARULCreation'); $insertSPARUL = array(); $insertSPARUL['insert_triples'] = array(); $insertSPARUL['insert_annotations'] = array(); $globalannotationpattern = ""; $globaltriplepattern = ""; foreach ($this->tripleFromExtractor as $triple) { $pattern = $triple->toSPARULPattern($this->storespecific); $insertSPARUL['insert_triples'][] = 'INSERT INTO GRAPH <' . $graphURI . '> { ' . $pattern . ' }'; $globaltriplepattern .= $pattern; $annotations = $triple->getOWLAxiomAnnotations(); Statistics::increaseCount('Total', 'createdAnnotations', count($annotations)); if (count($annotations) > 0) { $pattern = ""; foreach ($annotations as $ann) { $current = $ann->toSPARULPattern($this->storespecific); $pattern .= $current; $globalannotationpattern .= $current; } //annotations for one triple are aggregated to one query $insertSPARUL['insert_annotations'][] = 'INSERT INTO GRAPH <' . $annotationGraphURI . '> { ' . $pattern . ' }'; } } $insertSPARUL['globalAnnotationPattern'] = 'INSERT INTO GRAPH <' . $annotationGraphURI . '> { ' . $globalannotationpattern . ' }'; $insertSPARUL['globalTriplePattern'] = 'INSERT INTO GRAPH <' . $graphURI . '> { ' . $globaltriplepattern . ' }'; Timer::stop('LiveUpdateDestination::diffItOWLAxioms::insertSPARULCreation'); $result = array(); $result['del'] = $deleteSPARUL; $result['ins'] = $insertSPARUL; //print_r($result);die; Timer::stop('LiveUpdateDestination::diffItOWLAxioms::generationOfSPARULqueries'); return $result; }
private function _odbc_sparul_delete_language_oneQuery($graphURI, $languageProperties) { //*********************** //LANGUAGE //*********************** //delete all triples with the current subject //where the lang properties with string object //from other language version are given, which should stay Timer::start('LiveUpdateDestination::_odbc_sparul_delete_english_total'); $union = array(); foreach ($languageProperties as $one) { $u = new URI($one, false); $union[] = '?p = ' . $u->toSPARULPattern(); } $filter = TripleDiff::assembleTerms($union, '||'); //$filter =''; $sparul = 'DELETE FROM <' . $graphURI . '> { ' . $this->subjectSPARULpattern . ' ?p ?o } FROM <' . $graphURI . '> WHERE { ' . $this->subjectSPARULpattern . ' ?p ?o . FILTER ( ' . $filter . ' && (lang(?o) = \'en\')). }'; if ($this->_odbc_sparul_execute($sparul)) { $this->counterDelete += 1; } Timer::stop('LiveUpdateDestination::_odbc_sparul_delete_english_total'); $this->log(DEBUG, 'deleted language'); //TESTS>>>>>>>>>>>> if (Options::getOption('debug_run_tests')) { $this->log(INFO, 'no test for language currently'); } //TESTS<<<<<<<<<<< }