From: <sk...@us...> - 2008-10-28 13:45:06
|
Revision: 1469 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1469&view=rev Author: sknappe Date: 2008-10-28 10:10:34 +0000 (Tue, 28 Oct 2008) Log Message: ----------- new negativeExampleFinder using database Modified Paths: -------------- trunk/src/dbpedia-navigator/DLLearnerConnection.php trunk/src/dbpedia-navigator/helper_functions.php Modified: trunk/src/dbpedia-navigator/DLLearnerConnection.php =================================================================== --- trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-10-28 09:18:33 UTC (rev 1468) +++ trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-10-28 10:10:34 UTC (rev 1469) @@ -53,6 +53,7 @@ function getConceptFromExamples($posExamples,$negExamples,$number) { require_once("Settings.php"); + require_once("helper_functions.php"); $settings=new Settings(); $this->client->applyConfigEntryInt($this->id, $this->ksID, "recursionDepth",1); @@ -61,10 +62,11 @@ $this->client->applyConfigEntryString($this->id, $this->ksID, "predefinedManipulator", "DBPEDIA-NAVIGATOR"); $this->client->applyConfigEntryBoolean($this->id, $this->ksID, "useCache", true); if(empty($negExamples)){ - if ($settings->classSystem=="YAGO") $filterClasses=array("http://xmlns.com/foaf/","http://dbpedia.org/ontology/"); + /*if ($settings->classSystem=="YAGO") $filterClasses=array("http://xmlns.com/foaf/","http://dbpedia.org/ontology/"); else if ($settings->classSystem=="DBpedia") $filterClasses=array("http://xmlns.com/foaf/","http://dbpedia.org/class/yago/","http://dbpedia.org/ontology/Resource"); $negExamples=$this->client->getNegativeExamples($this->id,$this->ksID,$posExamples,count($posExamples),"http://dbpedia.org/resource/",$filterClasses); - $negExamples=$negExamples->item; + $negExamples=$negExamples->item;*/ + $negExamples=getNegativeExamplesFromParallelClass($posExamples); } $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "instances", array_merge($posExamples,$negExamples)); $this->client->setReasoner($this->id, "fastInstanceChecker"); Modified: trunk/src/dbpedia-navigator/helper_functions.php =================================================================== --- trunk/src/dbpedia-navigator/helper_functions.php 2008-10-28 09:18:33 UTC (rev 1468) +++ trunk/src/dbpedia-navigator/helper_functions.php 2008-10-28 10:10:34 UTC (rev 1469) @@ -616,4 +616,51 @@ if (isset($triples['http://dbpedia.org/property/utcDst'])) unset($triples['http://dbpedia.org/property/utcDst']); if (isset($triples['http://dbpedia.org/property/spokenWikipedia2Property'])) unset($triples['http://dbpedia.org/property/spokenWikipedia2Property']); } + +public function getNegativeExamplesFromParallelClass($posExamples){ + include_once('Settings.php'); + include_once('DatabaseConnection.php'); + //connect to the database + $settings=new Settings(); + $databaseConnection=new DatabaseConnection($settings->database_type); + $databaseConnection->connect($settings->database_server,$settings->database_user,$settings->database_pass); + $databaseConnection->select_database($settings->database_name); + + $examples=array(); + foreach ($posExamples as $pos){ + $query="SELECT category FROM articlecategories WHERE name='".$pos."' AND category!='http://dbpedia.org/ontology/Resource'"; + $res=$databaseConnection->query($query); + if ($databaseConnection->numberOfEntries($res)>0) $zufall = rand(1,$databaseConnection->numberOfEntries($res)); + $i=1; + while ($result=$databaseConnection->nextEntry($res)){ + if ($i==$zufall) $class=$result['category']; + $i++; + } + $query="SELECT father FROM classhierarchy WHERE child='".$class."'"; + $res=$databaseConnection->query($query); + if ($databaseConnection->numberOfEntries($res)>0) $zufall = rand(1,$databaseConnection->numberOfEntries($res)); + $i=1; + while ($result=$databaseConnection->nextEntry($res)){ + if ($i==$zufall) $father=$result['father']; + $i++; + } + + $query="SELECT child FROM classhierarchy WHERE father='".$father."' AND child!='".$class."'"; + $res=$databaseConnection->query($query); + if ($databaseConnection->numberOfEntries($res)>0) $zufall = rand(1,$databaseConnection->numberOfEntries($res)); + $i=1; + while ($result=$databaseConnection->nextEntry($res)){ + if ($i==$zufall) $child=$result['child']; + $i++; + } + $query="SELECT name FROM articlecategories WHERE category='".$child."' AND name!='".$pos."' ORDER BY RAND() LIMIT 1"; + $res=$databaseConnection->query($query); + if ($databaseConnection->numberOfEntries($res)>0){ + $result=$databaseConnection->nextEntry($res); + $examples[]=$result['name']; + } + } + + return $examples; +} ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |