private function _primaryStrategy()
 {
     /*
      * PREPARATION
      *
      * */
     if (!TheContainer::wasSet(LUD_SPARQLFILTER)) {
         $store = null;
         $tripleDiff = new TripleDiff($this->uri, $this->language, $this->producesFilterList, $store);
         TheContainer::set(LUD_SPARQLFILTER, $tripleDiff->createFilter($this->producesFilterList));
     }
     $this->odbc = ODBC::getDefaultConnection();
     $graphURI = $this->graphURI;
     $annotationGraphURI = $this->annotationGraphURI;
     $generateOWLAxiomAnnotations = $this->generateOWLAxiomAnnotations;
     /*
      * STRATEGIES FOR DELETION
      * */
     Timer::start('LiveUpdateDestination::_odbc_sparul_delete_total');
     $this->_odbc_clean_sparul_delete_subresources();
     $this->_odbc_sparul_delete_subject_not_static($graphURI, $this->subjectSPARULpattern, TheContainer::get(LUD_SPARQLFILTER));
     //$this->_odbc_sparul_delete_language($graphURI, $languageProperties );
     //$this->_odbc_sparul_delete_language_oneQuery($graphURI, $languageProperties );
     Timer::stop('LiveUpdateDestination::_odbc_sparul_delete_total');
     /*
      * STRATEGIES FOR INSERTION
      * will do nothing if Options::getOption('debug_turn_off_insert') is true
      * */
     $this->_odbc_ttlp_insert_triples($this->tripleFromExtractor);
     $this->log(INFO, 'no of queries, insert: ' . $this->counterInserts . ' delete: ' . $this->counterDelete . ' odbc_total: ' . $this->counterTotalODBCOperations);
     /*
             if(Options::getOption('writeSPARULtoFiles')){
                 $this->writeSPARULtoFiles($deleteSPARUL, $insertSPARUL);
             }
     */
 }
    public function smarterDiffItOWLAxioms()
    {
        Timer::start('LiveUpdateDestination::diffItOWLAxioms::total');
        Timer::start('LiveUpdateDestination::diffItOWLAxioms::preparation');
        //a store is needed for language here
        $store = null;
        //$store = new SPARQLToRDFTriple($this->uri, $this->language);
        $propLangFilter = Options::getOption('stringPredicateWithForeignlanguages');
        $graphURI = Options::getOption('graphURI');
        $annotationGraphURI = Options::getOption('annotationGraphURI');
        //generate the regex filter according to namespaces
        //includes language properties
        foreach ($propLangFilter as $one) {
            $this->predicateFilterList[] = $one;
        }
        $tripleDiff = new TripleDiff($this->uri, $this->language, $this->predicateFilterList, $this->objectFilterList, $this->predicateObjectFilterList, $store);
        $filterForNotAnnotatedTriples = $tripleDiff->createFilter($this->predicateFilterList, $this->objectFilterList, $this->predicateObjectFilterList);
        //$langTriples = $store->getRDFTripleForLangProperties($propLangFilter);
        //create a filter for extractors
        $subjectpattern = $this->uri->toSPARULPattern($this->storespecific);
        /*
                    $extractedByPattern = RDFtriple::URI(DBM_ORIGIN)->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,'||').') . ';
        */
        $preparation = Timer::stop('LiveUpdateDestination::diffItOWLAxioms::preparation');
        $this->log(TRACE, 'prep needed: ' . $preparation);
        //***********************
        //DELETE ALL NON STATIC TRIPLES
        //**********************
        //delete all triples with the current subject
        //according to the filters
        //do not delete special properties see below
        //Timer::start('LiveUpdateDestination::diffItOWLAxioms::notAnnotated');
        $deleteSPARUL['delete_with_subject_not_static'] = 'DELETE  FROM <' . $graphURI . '>
    { ' . $subjectpattern . ' ?p ?o }
WHERE {
    ' . $subjectpattern . ' ?p ?o .
    FILTER (' . $filterForNotAnnotatedTriples . ').
}';
        //***********************
        //LANGUAGE
        //***********************
        //delete all triples with the current subject
        //where the lang properties with string object
        //from other language version are given, which should stay
        $x = 0;
        //var_dump($langTriples);
        foreach ($propLangFilter as $one) {
            $u = new URI($one, false);
            $deleteSPARUL['delete_english' . $x++] = 'DELETE FROM GRAPH <' . $graphURI . '>
{ ' . $subjectpattern . ' ' . $u->toSPARULPattern($this->storespecific) . ' ?o }
WHERE {
    ' . $subjectpattern . ' ' . $u->toSPARULPattern($this->storespecific) . ' ?o .
    FILTER ( lang(?o) = \'en\').
}';
        }
        //****************************
        //DELETE ANNOTATIONS
        //****************************
        //delete the corresponding annotations
        $deleteSPARUL['delete_corresponding_annotations'] = 'DELETE  FROM <' . $annotationGraphURI . '>
    { ?axiom ?axp  ?axo .  }
WHERE {
    ?axiom <' . OWL_SUBJECT . '> ' . $subjectpattern . ' .
    ?axiom ?axp  ?axo .
}';
        //echo $deleteSPARUL['delete_corresponding_annotations'] ;die;
        //***********************
        //MISSING: DELETE ANOMALIES I.E. source Page
        //***********************
        //TODO go to infobox extractor and
        //add an annotation to all subject/rating objects to which subject they belong
        //and then delete them also
        /*
        $deleteSPARUL['delete_anomalies'] =
        'DELETE  FROM <' . $annotationGraphURI . '>
            { ?axiom ?axp  ?axo .  }
        WHERE {
            ?axiom <'.DBM_ONDELETECASCADE.'> '.$subjectpattern.' .
            ?axiom ?axp  ?axo .
        }';
        */
        //**********************
        //GENERATE NEW TRIPLES
        //**********************
        Timer::start('LiveUpdateDestination::diffItOWLAxioms::insertSPARULCreation');
        $insertSPARUL = array();
        $insertSPARUL['insert_triples'] = array();
        $insertSPARUL['insert_annotations'] = array();
        $globalannotationpattern = "";
        $globaltriplepattern = "";
        $this->log(DEBUG, 'number of triples: ' . count($this->tripleFromExtractor));
        foreach ($this->tripleFromExtractor as $triple) {
            $pattern = $triple->toSPARULPattern($this->storespecific);
            $insertSPARUL['insert_triples'][] = 'INSERT INTO GRAPH <' . $graphURI . '> { ' . $pattern . ' }';
            $globaltriplepattern .= $pattern . "\n";
            $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 . "\n";
                }
                //annotations for one triple are aggregated to one query
                $insertSPARUL['insert_annotations'][] = 'INSERT INTO GRAPH <' . $annotationGraphURI . '> { ' . $pattern . ' }';
            }
        }
        $this->log(DEBUG, 'number of annotation inserts: ' . count($insertSPARUL['insert_annotations']));
        $insertSPARUL['globalAnnotationPattern'] = 'INSERT INTO GRAPH <' . $annotationGraphURI . '> { ' . $globalannotationpattern . ' }';
        $insertSPARUL['globalTriplePattern'] = 'INSERT INTO GRAPH <' . $graphURI . '> { ' . $globaltriplepattern . ' }';
        $this->log(DEBUG, 'length globalTriplePattern: ' . strlen($insertSPARUL['globalTriplePattern']));
        $this->log(DEBUG, 'length globalAnnotationPattern: ' . strlen($insertSPARUL['globalAnnotationPattern']));
        Timer::stop('LiveUpdateDestination::diffItOWLAxioms::insertSPARULCreation');
        $result = array();
        $result['del'] = $deleteSPARUL;
        $result['ins'] = $insertSPARUL;
        Timer::stop('LiveUpdateDestination::diffItOWLAxioms::total');
        return $result;
    }
 private function _prepare($languageProperties)
 {
     if (!TheContainer::wasSet(LUD_SPARQLFILTER)) {
         $store = null;
         $tripleDiff = new TripleDiff($this->uri, $this->language, $this->producesFilterList, $store);
         TheContainer::set(LUD_SPARQLFILTER, $tripleDiff->createFilter($this->producesFilterList));
     }
     if (!TheContainer::wasSet(LUD_SPARQLFILTERWITHLANGUAGES)) {
         $store = null;
         $producesFiltertmp = $this->producesFilterList;
         foreach ($languageProperties as $one) {
             $producesFiltertmp[] = array('type' => EXACT, 's' => '', 'p' => $one, 'o' => '');
         }
         $tripleDiff = new TripleDiff($this->uri, $this->language, $producesFiltertmp, $store);
         TheContainer::set(LUD_SPARQLFILTERWITHLANGUAGES, $tripleDiff->createFilter($producesFiltertmp));
     }
 }