public function getConceptsByTag($OntologyID = '1', $Tag, $userId = '1') { if (empty($Tag)) { return null; } $TagLabel = $Tag->getLabel(); //Going curl! $url = $this->_mapping_endpoint . $OntologyID . '/mapping'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); $params = "tag={$TagLabel}&userId={$userId}&doGreedyMatch=false"; //TODO set variable userid!!!!! curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $xmlanswer = curl_exec($ch); curl_close($ch); //No answer from tagonto if (empty($xmlanswer)) { return array(); } //Answer gotten //TODO error handling! $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; //Loading the XML doc $doc->LoadXML($xmlanswer); $xpath = new DOMXPath($doc); //Extracting tag information $query = '//mapping'; //TODO error handling here too $mappings = $xpath->query($query); //Setupping ontologyconcepts foreach ($mappings as $mapping) { $concept = new OntologyConcept(); //Setting name and uri $concept->setName($mapping->getAttribute('concept')); $concept->setUri($mapping->getAttribute('conceptUri')); echo $CONCEPTS_TABLE; //Here we get the element ID $ONT = new Ontology($OntologyID); $concept->setId($ONT->getConceptIDFromURI($mapping->getAttribute('conceptUri'))); //Preparing an array that will be merged to a given element mapping //TODO caching here?! $maparray[1] = $mapping->getAttribute('significance'); $tagarray[$mapping->getAttribute('tag')] = $maparray; $concept->addAssociatedTag($tagarray); $Concepts[] = $concept; } return $Concepts; }
public function getTree($node, $ontology) { $filename = getcwd() . "/cache/onto-" . urlencode($ontology->url) . ".json"; if (is_readable($filename)) { return json_decode(file_get_contents($filename)); } $count = new PrefixCounter($ontology->prefix); $graph = new Graphite(); $xml = simplexml_load_file($ontology->url); foreach ($xml->getNamespaces(true) as $prefix => $uri) { $graph->ns($prefix, stripslashes($uri)); } $graph->load($ontology->url); $classes = $graph->allOfType("owl:Class"); $classes = $classes->append($graph->allOfType("rdfs:Class")); $toplevel = $classes->except($classes->all("-rdfs:subClassOf")); $json = array(); foreach ($toplevel as $class) { $uri = $graph->shrinkUri($class); $children = Ontology::getChildren($graph, $class, $count); $count->step(); $json[] = array("id" => $count->value(), "text" => $uri, "iconCls" => "class", "children" => $children, "leaf" => empty($children)); } file_put_contents($filename, json_encode($json)); return $json; }
public function getByPrefix($prefix) { try { return \Ontology::where('prefix', $prefix)->firstOrFail()->toArray(); } catch (ModelNotFoundException $ex) { return null; } }
/** * Seed the prefixes table based on the prefixes json file * * @return void */ private function seedPrefixes() { // Empty the ontology table \Ontology::truncate(); // Fetch the ontology from the json file $prefixes = json_decode(file_get_contents(app_path() . '/database/seeds/data/prefixes.json'), true); foreach ($prefixes as $prefix => $uri) { \Ontology::create(array('prefix' => $prefix, 'uri' => $uri)); } $this->command->info("Added the prefixes and corresponding uri's."); }
<?php //include require_once '../config.php'; $ontology = new Ontology($ONTOLOGYID); $tagToMap = $_GET['tag']; //TODO here a function to get all concepts in the ontology $ontologyConcepts = $ontology->getAllConcepts(); //counter used to set the number of columns in the table $i = 0; //$ontologyConcepts = array("uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove", "dieci", "undici", "dodici", "tredici"); ?> <div id="wholeOntology"> <table> <tr> <?php foreach ($ontologyConcepts as $concept) { ?> <td><a onclick="choosedConcept('<?php echo $concept->getId(); ?> ','<?php echo $tagToMap; ?> ');"><?php echo $concept->getName(); ?> </a></td> <?php
<?php /** * This translator will OUTPUT a div containing all the code needed to show the Concept selected * by the user for the mapping, together with its linked concepts to allow navigability */ require_once '../config.php'; //Getting parameters $conceptIDToShow = $_GET['concept']; $tag = $_GET['tag']; //to avoid setting tag to map if the caller function is navigationConcept $isOnlyNavigation = $_GET['noTag']; //Creating classes $res = new ReasoningManager($TAGONTOLIB_MAPPING_ENDPOINT); $Ontology = new Ontology($ONTOLOGYID); //Retrieving the mapped concept by ID $mappedConcept = $Ontology->getConceptById($conceptIDToShow); //Adding support for reinforcement mapping $logman = new LoginManager(); //if the user is logged if ($logman->isLoggedin()) { $user = $logman->getLoggedUserDetails(); if (!$isOnlyNavigation) { $res->mapTagOnConcept(new Tag($tag), $mappedConcept, $user['id'], $user['significance'], $ONTOLOGYID); } } //Error handling if ($mappedConcept == null) { die('Mapped concept is null!'); } ?>