public static function display($title) { $cache = $GLOBALS['okwCache']; $html = ''; $titleArray = explode(':', $title); $ontAbbr = $titleArray[0]; $termID = str_replace(' ', '_', $titleArray[1]); $ontology = new OntologyData($ontAbbr); $term = $ontology->parseTermByID($termID); if (!empty($cache['hierarchy']) || !empty($cache['axiom']['subclassof']) || !empty($cache['axiom']['equivalent'])) { $html .= self::printPageSidebar($ontology, $term, $cache); } if ($ontology->existClass($term->iri) || !empty($cache['annotation'])) { $html .= self::printPageHeader($ontology, $term, $cache); } return DisplayHelper::tidyHTML($html); }
protected static function describeFieldHTML($perm, $term) { $types = $GLOBALS['okwRDFConfig']['type']; $html = '<table id="okw-describe-main" class="main">'; $html .= '<tr><td><label id="okw-describe-label" class="term-label"><strong>Label: </strong></label>'; $html .= '<input id="okw-describe-label-input" class="term-input-label" name="term-label" value="'; $html .= $term->label; $html .= '"></td>'; $html .= '<td><label id="okw-describe-iri" class="term-iri"><strong>IRI: </strong></label>'; $html .= '<input id="okw-describe-iri-input" class="term-input-iri" name="term-iri" value="'; $html .= $term->iri; if ($perm == FormEditAction::ONTOLOGY_MASTER) { $html .= '"></td>'; } else { $html .= '" readonly></td>'; } $html .= '<td><label id="okw-describe-type" class="type"><strong>Type: </strong></label>'; if ($perm == FormEditAction::ONTOLOGY_MASTER) { $html .= '<select id="okw-describe-type-select" class="term-select-type" name="term-type">'; } else { $html .= '<select id="okw-describe-type-select" class="term-select-type" name="term-type" disabled>'; } foreach ($types as $type) { $typeLabel = DisplayHelper::getShortTerm($type); $html .= '<option value="'; $html .= $type; if ($typeLabel == $term->type) { $html .= '" selected>'; } else { $html .= '">'; } $html .= $typeLabel; $html .= '</option>'; } $html .= '</select></td>'; $html .= '</tr></table>'; return $html; }
public static function extractSupClass($params, $ontology) { $options = array(); $valids = array(); $invalids = array(); $supClasses = array(); foreach ($params as $param) { $index = uniqid(); $pair = explode('=', $param, 2); if (count($pair) == 2) { $name = $pair[0]; $name = preg_replace('/[\\s]*(<!--.*?(?=-->)-->)[\\s]*/', '', $name); $name = strtolower(trim($name)); $value = $pair[1]; $value = preg_replace('/[\\s]*(<!--.*?(?=-->)-->)[\\s]*/', '', $value); $value = trim($value); $options[$index][] = $name; $options[$index][] = $value; if ($name == 'subclassof') { if (strtolower($value) == 'thing') { $supClassIRI = $GLOBALS['okwRDFConfig']['Thing']; $valids[$index]['iri'] = $supClassIRI; $valids[$index]['id'] = DisplayHelper::getShortTerm($supClassIRI); $valids[$index]['title'] = DisplayHelper::getShortTerm($supClassIRI); } else { $supClassIRI = $ontology->convertToIRI($value); $term = $ontology->parseTermByIRI($supClassIRI); if (!is_null($term)) { $title = $ontology->getOntAbbr() . ':' . $term->id; if (OntologyValidator::isExistTitleText($title)) { $valids[$index]['iri'] = $supClassIRI; $valids[$index]['id'] = $ontology->convertToID($supClassIRI); $valids[$index]['title'] = $ontology->convertToTitle($supClassIRI); } else { $invalids[$index] = self::ERROR_INVALID_TERM; } } else { $invalids[$index] = self::ERROR_INVALID_TERM; } } } else { $invalids[$index] = self::ERROR_INVALID_MAGICWORD; } } else { $options[$index][] = $param; $invalids[$index] = self::ERROR_EXCESS_INPUT; } } return array($options, $valids, $invalids); }
public function parseTermHierarchy($term, $pathType, $supClass = null) { /*if ( !is_object( $term ) ) { $term = $this->parseTermByIRI( $term ); }*/ $hierarchy = array(); $supClasses = array(); $sibClasses = array(); $subClasses = array(); $hasChild = array(); if (!preg_match('/http:\\/\\/.+/', $supClass)) { $tmpClass = $this->convertToIRI(array($supClass)); $supClass = $tmpClass[0]; } $supClassResults = $this->rdf->getTransitiveSupClass($this->graph, $pathType, $term->iri, $supClass); if (!empty($supClassResults)) { foreach ($supClassResults as $supClassResult) { foreach ($supClassResult as $supClassIRI => $supClassLabel) { if ($supClassLabel != '') { $supClasses[$supClassIRI] = $supClassLabel; } else { $supClasses[$supClassIRI] = DisplayHelper::getShortTerm($supClassIRI); } } if (!empty($supClasses)) { $tmpClasses = $supClasses; end($tmpClasses); $supClass = key($tmpClasses); $sibClassResult = $this->rdf->getSubClass($this->graph, $supClass); unset($sibClassResult[$term->iri]); foreach ($sibClassResult as $sibClassIRI => $sibClassObject) { $sibClasses[$sibClassIRI] = $sibClassObject->label; if ($sibClassObject->hasChild) { $hasChild[$sibClassIRI] = true; } else { $hasChild[$sibClassIRI] = false; } } } $subClassResult = $this->rdf->getSubClass($this->graph, $term->iri); foreach ($subClassResult as $subClassIRI => $subClassObject) { $subClasses[$subClassIRI] = $subClassObject->label; if ($subClassObject->hasChild) { $hasChild[$subClassIRI] = true; } else { $hasChild[$subClassIRI] = false; } } $hierarchy[] = array('path' => $supClasses, 'supClass' => $supClass, 'sibClasses' => $sibClasses, 'subClasses' => $subClasses, 'hasChild' => $hasChild); } } else { $subClassResult = $this->rdf->getSubClass($this->graph, $term->iri); foreach ($subClassResult as $subClassIRI => $subClassObject) { $subClasses[$subClassIRI] = $subClassObject->label; if ($subClassObject->hasChild) { $hasChild[$subClassIRI] = true; } else { $hasChild[$subClassIRI] = false; } } $hierarchy[] = array('path' => null, 'supClass' => null, 'sibClasses' => null, 'subClasses' => $subClasses, 'hasChild' => $hasChild); } return $hierarchy; }
public static function parseSearchResult($keywords, $graph, $searchResult) { $match = array(); $terms = array(); $count = 0; # IRI Match $results1 = array(); foreach ($searchResult as $result) { if (preg_match_all('/([a-zA-Z]+)[:_]([a-zA-Z]*)[:_]?(\\d+)/', $keywords, $matches, PREG_SET_ORDER)) { if ($matches[0][2] == '') { $searchTermURL = 'http://purl.obolibrary.org/obo/' . $matches[0][1] . '_' . $matches[0][3]; } else { $searchTermURL = 'http://purl.obolibrary.org/obo/' . $matches[0][2] . '_' . $matches[0][3]; } $term = array_pop(preg_split('/[\\/#]/', $result['s'])); if ($searchTermURL == $result['s']) { $count++; $match[] = array('id' => DisplayHelper::encodeURL($term), 'iri' => $result['s'], 'label' => $result['o']); $terms[$result['o']] = 1; } } } # Exact Match $results2 = array(); foreach ($searchResult as $result) { if (strtolower($result['o']) == strtolower($keywords)) { $term = array_pop(preg_split('/[\\/#]/', $result['s'])); if (!isset($terms[$result['o']])) { $count++; $match[] = array('id' => DisplayHelper::encodeURL($term), 'iri' => $result['s'], 'label' => $result['o']); $terms[$result['o']] = 1; } } else { $results2[] = $result; } } # Partial Match $results3 = array(); foreach ($searchResult as $result) { if ($count > 100) { break; } if (strpos(strtolower($result['o']), strtolower($keywords)) === 0) { $tokens = preg_split('/[\\/#]/', $result['s']); $term = array_pop($tokens); if (!isset($terms[$result['o']])) { $count++; $match[] = array('id' => DisplayHelper::encodeURL($term), 'iri' => $result['s'], 'label' => $result['o']); $terms[$result['o']] = 1; } } else { $results3[] = $result; } } # Remaining Match (Regular Expression Match return by SPARQL) foreach ($searchResult as $result) { if ($count > 100) { break; } $tokens = preg_split('/[\\/#]/', $result['s']); $term = array_pop($tokens); if (!isset($terms[$result['o']])) { $count++; $match[] = array('id' => DisplayHelper::encodeURL($term), 'iri' => $result['s'], 'label' => $result['o']); $terms[$result['o']] = 1; } } return $match; }
protected static function printCreateForm($perm, $ontAbbr, $label, $ontologies, $magic) { $html = self::printFormHeader(); $html .= '<input id="okw-form-ontology" type="hidden" value="">'; $html .= CreateDescribeHTML::getHTML($perm, $label, $ontologies); $html .= EditHierarchyHTML::getHTML(); $html .= EditAxiomHTML::getHTML($ontAbbr); $html .= EditAnnotationHTML::getHTML($magic); $html .= self::printFormBottom(); return DisplayHelper::tidyHTML($html); }
/** * Static function to generate Sub-Class Section HTML * * @param $subClasses * @param $hasChild * @return $html */ protected static function subClassSectionHTML($ontAbbr, $rootURL, $subClasses, $hasChild) { $subHasChildMax = $GLOBALS['okwHierarchyConfig']['subClassHasChildMax']; $subNoChildMax = $GLOBALS['okwHierarchyConfig']['subClassNoChildMax']; $html = '<!-- OKW Hierarchy Sub Class Opening -->'; $html .= '<ul>'; $noChildCount = 0; $hasChildCount = 0; $showMore = false; foreach ($subClasses as $subClassIRI => $subClassLabel) { if ($hasChildCount > $subHasChildMax && $noChildCount > $subNoChildMax) { break; } if ($subClassLabel == '') { $subClassLabel = DisplayHelper::getShortTerm($subClassIRI); } if ($hasChild[$subClassIRI] && $hasChildCount <= $subHasChildMax) { $hasChildCount++; $html .= '<li>+ '; $html .= self::entitiyHTML('sub-term', $rootURL . $ontAbbr . ':' . DisplayHelper::getShortTerm($subClassIRI), $subClassLabel); $html .= '</li>'; } elseif ($hasChildCount > $subHasChildMax) { $showMore = true; } if (!$hasChild[$subClassIRI] && $noChildCount <= $subNoChildMax) { $noChildCount++; $html .= '<li>- '; $html .= self::entitiyHTML('sub-term', $rootURL . $ontAbbr . ':' . DisplayHelper::getShortTerm($subClassIRI), $subClassLabel); $html .= '</li>'; } elseif ($noChildCount > $subNoChildMax) { $showMore = true; } } if ($showMore) { #TODO: Modify add remaining terms as hiddenthat trigger base on display more checkbox $html .= self::moreHTML('sub'); } $html .= '</ul>'; $html .= '<!-- OKW Hierarchy Sub Class Closing -->'; return $html; }
private function importAnnotationProperty($ontID, $options, $sql, $rdf, $graph) { $prefixNS = $GLOBALS['okwRDFConfig']['prefixNS']; $iris = $rdf->getSubject($graph, $prefixNS['rdf'] . 'type', $prefixNS['owl'] . 'AnnotationProperty'); $iris = $rdf->getLabel($graph, $iris); $annotations = array(); foreach ($iris as $iri => $label) { if ($iri == $prefixNS['rdfs'] . 'label') { continue; } $id = DisplayHelper::getShortTerm($iri); $label = str_replace(' ', '_', $label); $annotations[$id]['id'] = $id; $annotations[$id]['iri'] = $iri; $annotations[$id]['magicword'] = $label; if (preg_match('/([\\w\\d]*)_[\\d]+/', $id, $match)) { $annotations[$id]['ontology'] = $match[1]; if ($options['ontology_abbrv'] == $match[1]) { $annotations[$id]['source'] = $options['ontology_url']; } } } $sql->insertAnnotationProperty($ontID, $annotations); }
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; }
private static function doMap($term, $mapping) { if (array_key_exists($term, $mapping)) { return $mapping[$term]; } else { return DisplayHelper::getShortTerm($term); } }