Exemplo n.º 1
0
 public function doUpdate($title, $wikiText)
 {
     list($wikiText, $annotations) = AnnotationParser::reformatWikiText($wikiText);
     list($wikiText, $axioms) = AxiomParser::reformatWikiText($this->ontology->getOntAbbr(), $wikiText);
     list($wikiText, $supClasses) = HierarchyParser::reformatWikiText($this->ontology->getOntAbbr(), $wikiText);
     $this->updateAnnotations($annotations);
     $this->updateSubClassOf($supClasses, $axioms['subclassof']);
     $this->updateEquivalent($axioms['equivalent']);
     list($wikiText, $common) = CommonParser::reformatWikiText($wikiText);
     if (array_key_exists('label', $common)) {
         $this->updateLabel($common['label']);
     }
     return $wikiText;
 }
Exemplo n.º 2
0
 protected function doSave()
 {
     global $wgUser;
     $action = $this;
     $article = $this->page;
     $title = $article->getTitle();
     $output = $action->getOutput();
     $titleArray = explode(':', $title->getText());
     $ontAbbr = $titleArray[0];
     $termID = str_replace(' ', '_', $titleArray[1]);
     $update = new OntologyUpdate($ontAbbr, $termID);
     if ($title->exists()) {
         $wikiText = $article->getPage()->getContent()->getWikitextForTransclusion();
     } else {
         $wikiText = '';
     }
     /*
     if ( $title->exists() ) {
     	if ( $this->perm >= self::ONTOLOGY_MANAGER ) {
     		#$update->updateSubClassOf( $this->options['subclassof'] );
     	} else if ( $this->perm == self::ONTOLOGY_MASTER ) {
     		$update->updateIRI( $this->options['term-iri'] );
     		$update->updateType( $this->options['term-type'] );
     	}
     } else {
     	if ( $this->perm >= self::ONTOLOGY_PUBLIC ) {
     		#$update->updateSubClassOf( $this->options['subclassof'] );
     		$update->updateType( $this->options['term-type'] );
     	}
     }
     
     $update->updateLabel( $this->options['term-label'] );
     
     if ( key_exists( 'annotation-type', $this->options ) && key_exists( 'annotation-text', $this->options ) ) {
     	$newWikiText = ActionHelper::changeOntologyAnnotation( $oldWikiText,
     			$this->options['annotation-type'],
     			$this->options['annotation-text']
     	);
     }
     */
     if ($this->perm >= self::ONTOLOGY_USER) {
         if ($this->perm == self::ONTOLOGY_MASTER) {
             if ($title->exists()) {
                 $update->updateIRI($this->options['term-iri']);
                 $update->updateType($this->options['term-type']);
             } else {
                 $update->updateType($this->options['term-type']);
             }
             wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: %s is allowed {ontology_master}: updated restricted information about the term [[%s]]', $wgUser->getName(), $title->getText()));
         }
         $common['label'] = $this->options['term-label'];
         list($wikiText, $common) = CommonParser::reformatWikiText($wikiText, $common);
         wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: reformatted common information wikitext of the term [[%s]]', $title->getText()));
         $update->updateLabel($common['label']);
         wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: updated common information about the term [[%s]]', $title->getText()));
         if (array_key_exists('annotation-type', $this->options) && array_key_exists('annotation-text', $this->options)) {
             if (sizeof($this->options['annotation-type']) != sizeof($this->options['annotation-text'])) {
                 #TODO: Throw Exception
             }
             $sql = new SQLStore(wfGetDB(DB_SLAVE));
             $magic = $sql->getAnnotationMagicWords();
             $annotations = array();
             foreach ($this->options['annotation-type'] as $index => $name) {
                 $iri = $magic[$name]['iri'];
                 $text = $this->options['annotation-text'][$index];
                 $annotations[$iri][] = $text;
             }
             list($wikiText, $annotations) = AnnotationParser::reformatWikiText($wikiText, $annotations);
             wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: reformatted annotation wikitext of the term [[%s]]', $title->getText()));
             $update->updateAnnotations($annotations);
             wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: updated annotation of the term [[%s]]', $title->getText()));
         }
         if (array_key_exists('subclassof', $this->options)) {
             list($wikiText, $supClasses) = HierarchyParser::reformatWikiText($ontAbbr, $wikiText, $this->options['subclassof']);
             wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: reformatted hierarchy wikitext of the term [[%s]]', $title->getText()));
         }
         if (array_key_exists('axiom-type', $this->options) && array_key_exists('axiom-text', $this->options)) {
             if (sizeof($this->options['axiom-type']) != sizeof($this->options['axiom-text'])) {
                 #TODO: Throw Exception
             }
             $axioms = array();
             foreach ($this->options['axiom-type'] as $index => $type) {
                 $axioms[$index]['type'] = $type;
                 $axioms[$index]['text'] = $this->options['axiom-text'][$index];
             }
             list($wikiText, $axioms) = AxiomParser::reformatWikiText($ontAbbr, $wikiText, $axioms);
             wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: reformatted axiom wikitext of the term [[%s]]', $title->getText()));
         }
         $update->updateSubClassOf($supClasses, $axioms['subclassof']);
         wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: updated hierarchy of the term [[%s]]', $title->getText()));
         #TODO: Equivalent update
         wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: updated axiom of the term [[%s]]', $title->getText()));
     }
     $editor = $this->setupEditPage($wikiText);
     return $this->doMWStore($output, $title, $editor);
 }
Exemplo n.º 3
0
 private function importOntology()
 {
     $tmp = sys_get_temp_dir() . '/OntoKiWiQueue/';
     if (file_exists($tmp)) {
         $this->recursiveRemoveDirectory($tmp);
     }
     mkdir($tmp);
     if (array_key_exists('OntoKiWi', $GLOBALS['wgDebugLogGroups'])) {
         $log = $GLOBALS['wgDebugLogGroups']['OntoKiWi'];
     } else {
         if ($GLOBALS['wgDebugLogFile'] && $GLOBALS['wgDebugLogFile'] != '') {
             $log = $GLOBALS['wgDebugLogFile'];
         } else {
             $log = sys_get_temp_dir() . '/mediawikiimportfromtext.log';
         }
     }
     $request = $this->getRequest();
     $options = $request->getValues();
     $ontAbbr = $options['ontology_abbrv'];
     $graph = $options['ontology_graph_url'];
     $fullname = $options['ontology_fullname'];
     $id = strtolower($ontAbbr);
     $sql = new SQLStore(wfGetDB(DB_MASTER));
     $status = $sql->insertOntology($id, $options);
     if ($status) {
         wfDebugLog('OntoKiWi', sprintf('OKW\\Special\\ImportOntology: valid ontology: queued pages will be stored in $s', $tmp));
         $ontology = new OntologyData($ontAbbr);
         $rdf = $ontology->getRDF();
         $this->importObjectProperty($id, $options, $sql, $rdf, $graph);
         $this->importAnnotationProperty($id, $options, $sql, $rdf, $graph);
         $ontID = $sql->getOntologyID($ontAbbr);
         $annotationMagic = $sql->getAnnotationMagicWords($ontID);
         $objectMagic = $sql->getObjectMagicWords($ontID);
         $objects = array();
         foreach ($objectMagic as $magic => $object) {
             $objects[$magic] = $magic;
             $objects[$object['iri']] = $magic;
             $objects[$object['id']] = $magic;
         }
         $operations = array();
         foreach ($GLOBALS['okwRDFConfig']['restriction']['operation'] as $operation => $operationIRI) {
             $operations[$operationIRI] = $operation;
             $operations[$operation] = $operation;
         }
         $types = array();
         foreach ($GLOBALS['okwRDFConfig']['restriction']['type'] as $type => $typeIRI) {
             $types[$typeIRI] = $type;
             $types[$type] = $type;
         }
         $count = $rdf->countAllClass($graph);
         if ($count >= 10000) {
             $source = file_get_contents($options['source']);
             preg_match_all('/xmlns:([\\w]*)[\\s]?=[\\s]?"([^"]*)"[\\s]?/', $source, $matches, PREG_SET_ORDER);
             $prefix = array();
             foreach ($matches as $match) {
                 $prefix[$match[1]] = $match[2];
             }
             if (preg_match_all('/[\\s]?<owl:Class[\\s]?rdf:about[\\s]?=[\\s]?"(&([\\w]*);)?([^"]*)"[\\s]?[\\/]?>/', $source, $matches, PREG_SET_ORDER)) {
                 $classes = array();
                 foreach ($matches as $match) {
                     if ($match[1] != '' && $match[2] != '') {
                         $classes[] = $prefix[$match[2]] . $match[3];
                     } else {
                         $classes[] = $match[3];
                     }
                 }
             } else {
                 $sql->deleteOntology($id);
                 return array(self::EXCESSIVE_CLASS, null);
             }
         } else {
             if ($count == 0) {
                 $sql->deleteOntology($id);
                 return array(self::NO_CLASS_FOUND, null);
             } else {
                 $classes = $rdf->getAllClass($graph);
             }
         }
         $filename = "Category:{$ontAbbr}";
         file_put_contents($tmp . $filename, $fullname);
         $output = array();
         foreach ($classes as $index => $class) {
             if ($class == $GLOBALS['okwRDFConfig']['Thing']) {
                 continue;
             }
             $term = $ontology->parseTermByIRI($class);
             $id = $term->id;
             $filename = "{$ontAbbr}:{$id}";
             if (!OntologyValidator::isValidTitleText($filename)) {
                 throw new MWException("Unable to process term: {$id}. Please check the correctness of the Ontology");
             }
             $related = $ontology->parseTermRelated($term);
             $wikiText = "[[Category:{$ontAbbr}]]";
             $title = Title::newFromText($filename);
             if ($title->exists()) {
                 continue;
             }
             $output[$class] = $term->label . " ({$ontAbbr}:{$id})";
             $annotations = array();
             foreach ($annotationMagic as $name => $value) {
                 if (array_key_exists($value['iri'], $related)) {
                     $annotations[$value['iri']] = $rdf->getObject($graph, $term->iri, $value['iri']);
                 }
             }
             list($wikiText, $annotations) = AnnotationParser::reformatWikiText($wikiText, $annotations);
             $axiomData = $rdf->getAxiom($graph, $term->iri);
             $axioms = array();
             foreach ($axiomData['subclassof'] as $data) {
                 $axiom = array();
                 $axiom['type'] = 'subclassof';
                 $axiom['text'] = ManchesterSyntaxHandler::writeRecursiveManchester($data, array_merge($objects, $operations, $types));
                 $axioms[] = $axiom;
             }
             foreach ($axiomData['equivalent'] as $data) {
                 $axiom = array();
                 $axiom['type'] = 'equivalent';
                 $axiom['text'] = ManchesterSyntaxHandler::writeRecursiveManchester($data, array_merge($objects, $operations, $types));
                 $axioms[] = $axiom;
             }
             list($wikiText, $axioms) = AxiomParser::reformatWikiText($ontAbbr, $wikiText, $axioms, true);
             $supClasses = array_keys($rdf->getSupClass($graph, $term->iri));
             if (empty($supClasses)) {
                 $supClasses = array($GLOBALS['okwRDFConfig']['Thing']);
             }
             list($wikiText, $supClasses) = HierarchyParser::reformatWikiText($ontAbbr, $wikiText, $supClasses);
             $common['label'] = $term->label;
             list($wikiText, $common) = CommonParser::reformatWikiText($wikiText, $common);
             file_put_contents($tmp . $filename, $wikiText);
         }
         wfDebugLog('OntoKiWi', 'OKW\\Special\\ImportOntology: ontology SPARQL query completes, pages will be created using maintenance scripts in the background');
         $cmd = "( cd {$tmp} && for file in *; do php " . $GLOBALS['IP'] . "/maintenance/edit.php -u bot \$file < \$file; done && rm -R /tmp/OntoKiWiQueue ) > {$log} 2>&1 &";
         exec($cmd, $output, $return);
         return array(self::SUCCESS, $output);
     } else {
         return array(self::INVALID_SPARQL, null);
     }
 }