PageRenderTime 51ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/tmp/learner_onestep.php

https://bitbucket.org/wormsbee/evalnke
PHP | 105 lines | 62 code | 17 blank | 26 comment | 3 complexity | 19f9245b29941fe48bbb15d363dec3d4 MD5 | raw file
  1. <?php
  2. include ("../inc/func.inc");
  3. // include ("instances_cats_checker.php");
  4. //$cat = "Canadian_Football_League_announcers";
  5. //var_dump(get_ins_category($cat));
  6. //var_dump(get_ins_category_sister($cat));
  7. //var_dump(get_categories_contain_ins(100, 100));
  8. $CategoryName = "Stone_bridges" ;
  9. $arrayposexample = array ();
  10. $arraynegexample = array ();
  11. $limit = 20;
  12. //
  13. $ListOfResultPosbyLearning = array ();
  14. $count_matching = 0;
  15. //
  16. echo "<br/>============= Instances of Category: 'Indian_film_score_composers' ============= <br/>";
  17. // $ListInstancesOfCategory = get_ins_category($CategoryName); // list of relevant examples (+)
  18. //print_r($ListInstancesOfCategory);
  19. echo "<br/>============= END: Instances of Category: 'Indian_film_score_composers' ============= <br/>";
  20. $ListInstancesOfCategory = get_ins_category_2($CategoryName); // list of relevant examples (+)
  21. $arrayposexample = get_random_uri($ListInstancesOfCategory, 5);
  22. echo "<xmp>";
  23. print_r($arrayposexample);
  24. echo "</xmp>";
  25. $ListInstancesOfCategorysSister = get_ins_category_sister($CategoryName); // list of non-relevant examples (-)
  26. $arraynegexample = get_random_uri($ListInstancesOfCategorysSister, 5);
  27. echo "<xmp>";
  28. print_r($arraynegexample);
  29. echo "</xmp>";
  30. // Learner with two lists of examples
  31. $dllearnerurl = "http://139.18.2.57:8888/interfaces/rest" ;
  32. $result = learn($dllearnerurl , $limit, $arrayposexample, $arraynegexample);
  33. echo "<xmp>";
  34. print_r ($result);
  35. echo "</xmp>";
  36. $sparqlQueryString = $result ["learningresult"]["sparql"];
  37. $sparqlQueryString = str_replace("SELECT", "SELECT DISTINCT", $sparqlQueryString);
  38. $defaultgraphURI = 'http://dbpedia.org';
  39. $ep = "http://hanne.aksw.org:8892/sparql?query=";
  40. /* EXECUTE THE RETURNED SPARQL QUERY */
  41. //$instancesOfreceivedClass = executeSparqlQuery($ep,$defaultgraphURI,$sparqlQueryString);
  42. $ListOfResultbyLearning = executeSparqlQuery_json ($sparqlQueryString, "subject");
  43. $ListOfResultPosbyLearning = array ();
  44. echo "<br/>============= results from executing the sparql query ============= <br/>";
  45. //print_r($instancesOfreceivedClass);
  46. foreach($ListOfResultbyLearning as $ins_uri) {
  47. foreach($ListInstancesOfCategory as $ins)
  48. {
  49. if($ins_uri === $ins) {
  50. $collectmachteditems[$ins] = 1 ;
  51. //echo "<font color='red'> Matched! </font>";
  52. $ListOfResultPosbyLearning [] = $ins; // collect all positive results
  53. // $allfoundeditems++;
  54. $count_matching++;
  55. }
  56. }
  57. }
  58. // END: Extract the uri from xml results
  59. echo "ListOfResultbyLearning \n";
  60. echo "<xmp>";
  61. print_r($ListOfResultbyLearning);
  62. echo "</xmp>";
  63. // Compare two arrays: ListOfResultbyLearning and ListOfResultPosbyLearning
  64. // to get an new arrays: ListOfResultNegbyLearning
  65. $ListOfResultNegbyLearning = array_diff($ListOfResultbyLearning,$ListOfResultPosbyLearning); // collect all negative results
  66. echo "<br/><font color='red'>Total Matching: ".$count_matching."</font> : <br/>";
  67. echo "<xmp>";
  68. var_dump($ListOfResultPosbyLearning); // List of the returned items which are matched agains the items of the specified category
  69. echo "</xmp>";
  70. // initial a new positive example list
  71. // $tmp = get_random_uri($ListOfResultPosbyLearning, 5);
  72. $arrayposexample = array_merge(get_random_uri($ListOfResultPosbyLearning, 5),$arrayposexample);
  73. //$arrayposexample = getRandListPosEx($ListOfResultPosbyLearning);
  74. echo "<br/>**** (+) Preparation a new list of postive examples for the next step **** <br/>";
  75. // var_dump(count(array_keys($arrayposexample)));
  76. echo "<xmp>";
  77. print_r($arrayposexample);
  78. echo "</xmp>";
  79. // initial a new negative example list
  80. //$tmp2 = get_random_uri($ListOfResultNegbyLearning, 5);
  81. //$tmp3 = $arraynegexample;
  82. $arraynegexample = array_merge(get_random_uri($ListOfResultNegbyLearning, 5),$arraynegexample);
  83. echo "<br/>**** (-) Preparation a new list of negative examples for the next step *** <br/>";
  84. //var_dump(count(array_keys($arraynegexample)));
  85. echo "<xmp>";
  86. print_r($arraynegexample);
  87. echo "</xmp>";
  88. ?>