/tmp/learner_onestep.php
PHP | 105 lines | 62 code | 17 blank | 26 comment | 3 complexity | 19f9245b29941fe48bbb15d363dec3d4 MD5 | raw file
- <?php
- include ("../inc/func.inc");
- // include ("instances_cats_checker.php");
- //$cat = "Canadian_Football_League_announcers";
- //var_dump(get_ins_category($cat));
- //var_dump(get_ins_category_sister($cat));
- //var_dump(get_categories_contain_ins(100, 100));
-
- $CategoryName = "Stone_bridges" ;
- $arrayposexample = array ();
- $arraynegexample = array ();
- $limit = 20;
-
- //
- $ListOfResultPosbyLearning = array ();
- $count_matching = 0;
- //
-
-
-
- echo "<br/>============= Instances of Category: 'Indian_film_score_composers' ============= <br/>";
- // $ListInstancesOfCategory = get_ins_category($CategoryName); // list of relevant examples (+)
- //print_r($ListInstancesOfCategory);
- echo "<br/>============= END: Instances of Category: 'Indian_film_score_composers' ============= <br/>";
-
- $ListInstancesOfCategory = get_ins_category_2($CategoryName); // list of relevant examples (+)
- $arrayposexample = get_random_uri($ListInstancesOfCategory, 5);
- echo "<xmp>";
- print_r($arrayposexample);
- echo "</xmp>";
- $ListInstancesOfCategorysSister = get_ins_category_sister($CategoryName); // list of non-relevant examples (-)
- $arraynegexample = get_random_uri($ListInstancesOfCategorysSister, 5);
- echo "<xmp>";
- print_r($arraynegexample);
- echo "</xmp>";
-
- // Learner with two lists of examples
- $dllearnerurl = "http://139.18.2.57:8888/interfaces/rest" ;
- $result = learn($dllearnerurl , $limit, $arrayposexample, $arraynegexample);
- echo "<xmp>";
- print_r ($result);
- echo "</xmp>";
-
- $sparqlQueryString = $result ["learningresult"]["sparql"];
- $sparqlQueryString = str_replace("SELECT", "SELECT DISTINCT", $sparqlQueryString);
- $defaultgraphURI = 'http://dbpedia.org';
- $ep = "http://hanne.aksw.org:8892/sparql?query=";
- /* EXECUTE THE RETURNED SPARQL QUERY */
- //$instancesOfreceivedClass = executeSparqlQuery($ep,$defaultgraphURI,$sparqlQueryString);
- $ListOfResultbyLearning = executeSparqlQuery_json ($sparqlQueryString, "subject");
- $ListOfResultPosbyLearning = array ();
- echo "<br/>============= results from executing the sparql query ============= <br/>";
- //print_r($instancesOfreceivedClass);
-
-
- foreach($ListOfResultbyLearning as $ins_uri) {
-
- foreach($ListInstancesOfCategory as $ins)
- {
- if($ins_uri === $ins) {
- $collectmachteditems[$ins] = 1 ;
- //echo "<font color='red'> Matched! </font>";
- $ListOfResultPosbyLearning [] = $ins; // collect all positive results
- // $allfoundeditems++;
- $count_matching++;
- }
- }
- }
-
- // END: Extract the uri from xml results
-
- echo "ListOfResultbyLearning \n";
- echo "<xmp>";
- print_r($ListOfResultbyLearning);
- echo "</xmp>";
- // Compare two arrays: ListOfResultbyLearning and ListOfResultPosbyLearning
- // to get an new arrays: ListOfResultNegbyLearning
- $ListOfResultNegbyLearning = array_diff($ListOfResultbyLearning,$ListOfResultPosbyLearning); // collect all negative results
-
-
- echo "<br/><font color='red'>Total Matching: ".$count_matching."</font> : <br/>";
- echo "<xmp>";
- var_dump($ListOfResultPosbyLearning); // List of the returned items which are matched agains the items of the specified category
- echo "</xmp>";
-
- // initial a new positive example list
- // $tmp = get_random_uri($ListOfResultPosbyLearning, 5);
- $arrayposexample = array_merge(get_random_uri($ListOfResultPosbyLearning, 5),$arrayposexample);
- //$arrayposexample = getRandListPosEx($ListOfResultPosbyLearning);
- echo "<br/>**** (+) Preparation a new list of postive examples for the next step **** <br/>";
- // var_dump(count(array_keys($arrayposexample)));
- echo "<xmp>";
- print_r($arrayposexample);
- echo "</xmp>";
-
- // initial a new negative example list
- //$tmp2 = get_random_uri($ListOfResultNegbyLearning, 5);
- //$tmp3 = $arraynegexample;
- $arraynegexample = array_merge(get_random_uri($ListOfResultNegbyLearning, 5),$arraynegexample);
- echo "<br/>**** (-) Preparation a new list of negative examples for the next step *** <br/>";
- //var_dump(count(array_keys($arraynegexample)));
- echo "<xmp>";
- print_r($arraynegexample);
- echo "</xmp>";
- ?>