示例#1
0
    protected static function supClassAxiomHTML($ontAbbr, $rootURL, $ontology, $term, $related, $axioms)
    {
        $sql = new SQLStore(wfGetDB(DB_SLAVE));
        $magics = $sql->getObjectMagicWords($ontAbbr);
        $objects = array();
        foreach ($magics as $magic => $iri) {
            $objects[$magic] = $magic;
            $objects[$iri] = $magic;
            $objects[DisplayHelper::getShortTerm($iri)] = $magic;
        }
        $operations = $GLOBALS['okwRDFConfig']['restriction']['operation'];
        $types = $GLOBALS['okwRDFConfig']['restriction']['type'];
        $html .= <<<END
<!-- OKW SupClass Axiom Display Start -->
<div id="okw-axiom-supclass-heading" class="supclass-heading">SubClassOf Axiom</div>
<div id="okw-axiom-supclass-main" class="supclass-main">
<ul>
END;
        foreach ($axioms as $axiom) {
            $axiomHTML = '<li>';
            $axiomArray = preg_split('/\\s|([()])/', $axiom, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
            foreach ($axiomArray as $word) {
                if ($word == '') {
                    continue;
                } else {
                    if (array_key_exists($word, $objects)) {
                        $objectLabel = $objects[$word];
                        $axiomHTML .= "<b>{$objectLabel}</b>";
                    } else {
                        if (array_key_exists($word, $types) || array_key_exists($word, $operations)) {
                            $axiomHTML .= " {$word} ";
                        } else {
                            if ($word == '(' || $word == ')') {
                                $axiomHTML .= $word;
                            } else {
                                $classIRI = $ontology->convertToIRI($word);
                                $classID = $related[$classIRI]->id;
                                $classLabel = $related[$classIRI]->label;
                                $axiomHTML .= <<<END
<a href="{$rootURL}{$ontAbbr}:{$classID}">{$classLabel}</a>
END;
                            }
                        }
                    }
                }
            }
            $axiomHTML .= '</li>';
            $html .= $axiomHTML;
        }
        $html .= <<<END
</ul></div>
<!-- OKW SupClass Axiom Display End -->
END;
        return $html;
    }
示例#2
0
    public static function reformatWikiText($ontAbbr, $wikiText, $validAxioms = null, $newWiki = false)
    {
        preg_match_all('/{{\\s*[#]?Axiom\\s*:[\\s]*[^|]([^}]*)}}/', $wikiText, $matches, PREG_SET_ORDER);
        $options = array();
        $valids = array();
        $invalids = array();
        if (!empty($matches) || !is_null($validAxioms)) {
            $ontology = new OntologyData($ontAbbr);
            $sql = new SQLStore(wfGetDB(DB_SLAVE));
            $magics = $sql->getObjectMagicWords($ontAbbr);
            $objects = array();
            foreach ($magics as $magic => $object) {
                $objects[$magic] = $object['iri'];
                $objects[$object['iri']] = $object['iri'];
                $objects[$object['id']] = $object['iri'];
            }
            $operations = $GLOBALS['okwRDFConfig']['restriction']['operation'];
            $types = $GLOBALS['okwRDFConfig']['restriction']['type'];
            foreach ($matches as $match) {
                preg_match_all('/[\\s]*[|]([^|]*)/', $match[1], $params, PREG_PATTERN_ORDER);
                list($option, $valid, $invalid) = self::extractAxiom($params[1], $ontology, $objects, $operations, $types, $newWiki);
                $options = array_merge($options, $option);
                $valids = array_merge($valids, $valid);
                $invalids = array_merge($invalids, $invalid);
            }
        }
        if (!is_null($validAxioms)) {
            $valids = array();
            $output = array();
            foreach ($validAxioms as $value) {
                $index = uniqid();
                $options[$index][] = $value['type'];
                $options[$index][] = $value['text'];
                list($valid, $data) = ManchesterSyntaxHandler::parseRecursiveManchester(true, $value['text'], $ontology, $objects, $operations, $types, $newWiki);
                if ($valid) {
                    $valids[$index]['type'] = $value['type'];
                    $valids[$index]['text'] = $value['text'];
                    $valids[$index]['data'] = $data;
                } else {
                    $invalids[$index] = self::ERROR_INVALID_SYNTAX;
                }
            }
        } else {
            $output = array();
            foreach ($valids as $axiom) {
                $output[$axiom['type']][] = $axiom['data'];
            }
        }
        #TODO: Duplication checking
        if (!empty($valids) || !empty($invalids)) {
            $text = <<<END
{{ #Axiom: <!-- Auto formatted ontology axiom wikitext -->
END;
            foreach ($valids as $index => $axiom) {
                $type = $axiom['type'];
                $value = $axiom['text'];
                $text .= <<<END

| {$type} = {$value}
END;
            }
            foreach ($invalids as $index => $error) {
                $msg = self::getErrorMessage($error);
                if (sizeof($options[$index]) == 1) {
                    $param = $options[$index][0];
                    $text .= <<<END

| {$msg} {$param}
END;
                } else {
                    $name = $options[$index][0];
                    $value = $options[$index][1];
                    $text .= <<<END

| {$msg} {$name} = {$value}
END;
                }
            }
            $text .= <<<END

}}

END;
        }
        $text .= preg_replace('/([\\s]?{{\\s*[#]?Axiom\\s*:[\\s]*[^|][^}]*}}[\\s]?)/', '', $wikiText);
        return array($text, $output);
    }