As an anonymous user, you can only add new data. If you would like to also modify existing data, please create an account and indicate your languages on your user page.

User:MartinMai/vocabulary viewer/mockup/retrieve.php

From OmegaWiki
Jump to: navigation, search

<?php

include_once("../../../wau_lib/functions_3.php"); include_once("functions.php");

require_once 'HTML/QuickForm.php';



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


<link rel="stylesheet" type="text/css" media="screen, projection" href="styles.css" /> <link rel="stylesheet" type="text/css" media="screen, projection" href="http://www.omegawiki.org/extensions/Wikidata/OmegaWiki/tables.css" /> <link rel="shortcut icon" href="http://www.omegawiki.org/favicon.ico" /> <title>OmegaWiki gateway</title> <style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "http://www.omegawiki.org/skins/monobook/main.css?55"; /*]]>*/</style> <link rel="stylesheet" type="text/css" media="print" href="http://www.omegawiki.org/skins/common/commonPrint.css?55" /> <link rel="stylesheet" type="text/css" media="handheld" href="http://www.omegawiki.org/skins/monobook/handheld.css?55" />

</head> <body>

<?php


if($_REQUEST['debug'] == 1){ print_r($_REQUEST); }

////////////////////////////////////////// // Instantiate the HTML_QuickForm object $form = new HTML_QuickForm('firstForm', 'get');


     $languages_suggs = array("eng"=>"eng",
                          "deu"=>"deu", 
                          "fra"=>"fra", 
                          "nld"=>"nld",
                          "ita"=>"ita");

$collections = array( '376317' => 'One laptop per child basic vocabulary', '376322' => 'Destinazione Italia');

if($_REQUEST['mode'] == 'trainer' && !$_REQUEST['trainer_step']){ $_REQUEST['trainer_step'] = '0'; }

// Set defaults for the form elements $form->setDefaults(array(

   'name' => 'From'

));



// Add some elements to the form $form->addElement('header', null, ); $form->addElement('select', 'mode', 'voc browser mode:', array('browser' => 'lookup dictionary', 'trainer' => 'vocabulary training')); if($_REQUEST['mode'] == 'trainer'){

$form->addElement('select', 'wdcollection', 'Collection to choose vocabulary from:', $collections); $form->addElement('select', 'wdlanguages_1', 'target language you want to train:', $languages_suggs); }else{ $form->addElement('select', 'wdlanguages_1', 'first output language:', $languages_suggs); } if($_REQUEST['settings'] == 1){ $form->addElement('text', 'wdlanguages_2', 'second output language:', array('value' => ,'size' => 6, 'maxlength' => 6)); $form->addElement('text', 'wdlanguages_3', 'third output language:', array('size' => 6, 'maxlength' => 6)); $form->addElement('text', 'wdlanguages_4', 'fourth output language:', array('size' => 6, 'maxlength' => 6)); $link = wau_lib::build_get_uri_2('settings', '0', ); echo '<a href="'.$link.'">hide settings and languages</a>'; }elseif($_REQUEST['mode'] == 'trainer' && ($_REQUEST['trainer_step'] == 0)){ $form->addElement('text', 'wdlanguages_2', 'first language you can understand:', array('size' => 6, 'maxlength' => 6)); $form->addElement('text', 'wdlanguages_3', 'second language you can understand:', array('size' => 6, 'maxlength' => 6)); $form->addElement('text', 'wdlanguages_4', 'third language you can understand:', array('size' => 6, 'maxlength' => 6));

}else{ $form->addElement('hidden', 'wdlanguages_2', 'first output language:', array('size' => 6, 'maxlength' => 6)); $form->addElement('hidden', 'wdlanguages_3', 'second output language:', array('size' => 6, 'maxlength' => 6)); $form->addElement('hidden', 'wdlanguages_4', 'third output language:', array('size' => 6, 'maxlength' => 6)); $link = wau_lib::build_get_uri_2('settings', '1', ); echo '<a href="'.$link.'">edit settings and languages</a>'; }

if($_REQUEST['definedmeaning']){ $expression_group[] = &HTML_QuickForm::createElement('text', 'expression', 'search expression:', array('value' => ,'size' => 20, 'maxlength' => 256)); $form->updateElementAttr('expression',array('value' => )); $expression_group[] = &HTML_QuickForm::createElement('text', 'wdexplanguage', 'source language of an expression
(leave blank to search all languages)', array('size' => 20, 'maxlength' => 256)); }else{ $expression_group[] = &HTML_QuickForm::createElement('text', 'expression', 'search expression:', array('size' => 20, 'maxlength' => 256)); $expression_group[] = &HTML_QuickForm::createElement('text', 'wdexplanguage', 'source language of an expression
(leave blank to search all languages)', array('size' => 20, 'maxlength' => 256)); }


$form->addGroup($expression_group, 'Expression', 'Expression', ' ', 0);

if($_REQUEST['settings'] == 1){ $form->addElement('text', 'definedmeaning', 'definedmeaning (word-id):', array('value' => , 'size' => 15)); }else{ }


$form->addElement('submit', null, 'set / update');

// Define filters and validation rules

// Try to validate a form

// Output the form $form->display(); // //////////////////////////////////////////

//echo nl2br((print_r($_REQUEST)))."
";

if(!$wdlanguages){ //echo "Set languages that you can understand"; }

$ow_api_url = 'http://kantoor.edia.nl/wikidata/api.php?action=wikidata';

if( ($_REQUEST['expression']) OR (($_REQUEST['trainer_step'] == '0') AND ($_REQUEST['wdcollection'])) OR ($_REQUEST['definedmeaning']) ){

$ow_api_url = $ow_api_url."&wdsections=def|syntrans";


if($_REQUEST['definedmeaning']){

$ow_api_url = wau_lib::build_get_uri_2('wdtype', 'definedmeaning', $ow_api_url); $ow_api_url = wau_lib::build_get_uri_2('wddmid', $_REQUEST['definedmeaning'], $ow_api_url); }elseif($_REQUEST['trainer_step'] == '0' AND (!($_REQUEST['expression']))){ $ow_api_url = wau_lib::build_get_uri_2('wdtype', 'randomdm', $ow_api_url); $ow_api_url = wau_lib::build_get_uri_2('wdcollection', $_REQUEST['wdcollection'], $ow_api_url); $ow_api_url = wau_lib::build_get_uri_2('wdexplanguage', $_REQUEST['wdexplanguage'], $ow_api_url); }else{ $ow_api_url = wau_lib::build_get_uri_2('wdtype', 'expression', $ow_api_url); $ow_api_url = wau_lib::build_get_uri_2('wdexpression', $_REQUEST['expression'], $ow_api_url); $ow_api_url = wau_lib::build_get_uri_2('wdexplanguage', $_REQUEST['wdexplanguage'], $ow_api_url); }


//3320 //dog http://141.13.222.103/wau/wau_0_5/ow/retrieve_neu.php?definedmeaning=966

//http://kantoor.edia.nl/wikidata/api.php?action=wikidata&wdexpression=casa&wdexplanguage=ita&wdsections=def%7Csyntrans%7Cdef%7Caltdef%7Csyntrans%7Csyntransann%7Cann%7Cclassatt%7Cclassmem%7Ccolmem%7Crel&wdlanguages=nld%7Ceng%7Cfra


$wdlanguages = array(); $wdlanguages[] = $wdlanguages_1; if($wdlanguages_2){ $wdlanguages[] = $wdlanguages_2; } if($wdlanguages_3){ $wdlanguages[] = $wdlanguages_3; } if($wdlanguages_4){ $wdlanguages[] = $wdlanguages_4; }


//print_r($wdlanguages);

$wdlanguages_ser = implode('|',$wdlanguages);

$ow_api_url = wau_lib::build_get_uri_2('wdlanguages', $wdlanguages_ser, $ow_api_url);


}

if($debug == 1){ echo $ow_api_url."
"; }


$content = mediawiki_lib::get_ow_content_1($ow_api_url);


$xml = new SimpleXMLElement($content); /* //echo $xml->movie[0]->plot; // "So this language. It's like..."

echo '
    '; foreach ($xml->body->{'defined-meaning'}->definition->{'translated-text-list'}->{'translated-text'} as $string){ echo "
  • ".$string."
  • ";

    }

    echo '
';
  1. echo "
    ".$xml->body->{'defined-meaning'}->definition->{'translated-text-list'}->{'translated-text'}[1];
echo '
    '; $i = 0; foreach($xml->body->{'defined-meaning'}->{'synonyms-translations-list'}->{'synonyms-translations'} as $string){ //echo "
    Expression:".$string; echo "
  • Expression: ".$xml->body->{'defined-meaning'}->{'synonyms-translations-list'}->{'synonyms-translations'}[$i]->expression; echo '
  • ';

    $i++; }

    echo '
';

foreach ($xml->movie as $movie) {

  echo $movie->plot, '
';

}

  • /


//print_r($xml->body->{'defined-meaning'});

echo '
    '; foreach($xml->body->{'defined-meaning'} as $defined_meaning){ sub_dm($xml, $defined_meaning, $wdlanguages); } echo '
';


function sub_dm($xml, $defined_meaning, $wdlanguages){

echo "
  • "; $link = wau_lib::build_get_uri_2(); $link = wau_lib::build_get_uri_2('definedmeaning', (string) $defined_meaning['defined-meaning-id'], $link); $link_ow = 'http://www.omegawiki.org?title='; $link_ow .= 'DefinedMeaning:('.(string) $defined_meaning['defined-meaning-id'].')'; echo '

    <a href="'.$link.'">dm: '.(string) $defined_meaning['defined-meaning-id'].'</a>

    ';

    echo '<a href="'.$link_ow.'" title="show and edit complete data at omegawiki.org">[edit at omegawiki.org]</a>';

    echo "

    definitions</h2>"; $link = wau_lib::build_get_uri_2('settings', '1', ); echo '<a href="'.$link.'">set languages</a>'; echo '
      '; if($_REQUEST['trainer_step'] == '0' || $_REQUEST['trainer_step'] == '1'){ $languages = array(); $languages[] = $wdlanguages[0]; }else{ $languages = $wdlanguages; } $definitions = get_definition($xml, $defined_meaning, $languages); foreach ($definitions['wdlanguage'] as $wdlanguage){ echo '
    • '; echo $wdlanguage.': '; echo current($definitions['translated_text']); echo '
    • ';

      next($definitions['translated_text']); }

      echo '
    ';


    if($_REQUEST['trainer_step'] == '0'){ echo build_trainer_link(1, $defined_meaning['defined-meaning-id']); }



    if(!($_REQUEST['trainer_step'] == '0')){

    echo "<h3>expressions / translations

    "; echo '
      '; if($_REQUEST['trainer_step'] == '1'){ $languages = array(); $languages[] = $wdlanguages[0]; }else{ $languages = $wdlanguages; } $expressions = get_expression($xml, $defined_meaning, $languages); foreach ($expressions['wdlanguage'] as $wdlanguage){ if((current($expressions['indentical_meaning'])) == '1'){ echo '
    • '; }else{ echo '
    • '; } #echo '
    • '; echo $wdlanguage.': '; echo ''.current($expressions['expression']).''; if((current($expressions['indentical_meaning'])) == '0'){ echo " (not identical) "; } echo '
    • ';

      next($expressions['expression']); next($expressions['indentical_meaning']); }

      echo '
    ';

    }


    if($_REQUEST['trainer_step'] == '1'){ echo build_trainer_link(2, $defined_meaning['defined-meaning-id']); }

    if($_REQUEST['trainer_step'] == '2'){ echo build_trainer_link(0, ); }

    /*

    echo '
      '; foreach($xml->xpath('//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]//synonyms-translations[@indentical-meaning="1"]/expression[@language="'.$wdlanguage.'"]') as $expression){ echo '
    • '.$expression.'
    • ';

      } foreach($xml->xpath('//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]//synonyms-translations[@indentical-meaning="0"]/expression[@language="'.$wdlanguage.'"]') as $expression){

      echo '
    • '.$expression.' (not identical)
    • ';

      }

      • /
      echo "";

      }

      function get_definition($xml, $defined_meaning, $wdlanguages){ $lang_rows['wdlanguage'] = array(); $lang_rows['translated_text'] = array();

      foreach($wdlanguages as $wdlanguage){ $lang_row = get_definition_sub_1($xml, $defined_meaning, $wdlanguage); $lang_rows['wdlanguage'] = array_merge($lang_rows['wdlanguage'], (array)$lang_row['wdlanguage']); $lang_rows['translated_text'] = array_merge($lang_rows['translated_text'], (array)$lang_row['translated_text']); } if($lang_rows['wdlanguage'][0] == ){ echo "leer"; $lang_row = get_definition_sub_1($xml, $defined_meaning, 'eng'); $lang_rows['wdlanguage'] = array_merge($lang_rows['wdlanguage'], (array)$lang_row['wdlanguage']); $lang_rows['translated_text'] = array_merge($lang_rows['translated_text'], (array)$lang_row['translated_text']);


      } //print_r($arr); return $lang_rows; }


      function get_definition_sub_1($xml, $defined_meaning, $wdlanguage){

      if($xml->xpath('//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]/definition/translated-text-list/translated-text[@language="'.$wdlanguage.'"]')){ foreach($xml->xpath('//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]/definition/translated-text-list/translated-text[@language="'.$wdlanguage.'"]') as $translated_text){

      $arr['wdlanguage'][] = $wdlanguage; $arr['translated_text'][] = (string) $translated_text; } } return $arr;

      }


      function get_expression($xml, $defined_meaning, $wdlanguages){ $lang_rows['wdlanguage'] = array(); $lang_rows['expression'] = array(); $lang_rows['indentical_meaning'] = array();

      foreach($wdlanguages as $wdlanguage){ $lang_row = get_expression_sub_1($xml, $defined_meaning, $wdlanguage); $lang_rows['wdlanguage'] = array_merge($lang_rows['wdlanguage'], (array)$lang_row['wdlanguage']); $lang_rows['expression'] = array_merge($lang_rows['expression'], (array)$lang_row['expression']); $lang_rows['indentical_meaning'] = array_merge($lang_rows['indentical_meaning'], (array)$lang_row['indentical_meaning']); } if($lang_rows['expression'][0] == ){ echo "leer"; $lang_row = get_expression_sub_1($xml, $defined_meaning, 'eng'); $lang_rows['wdlanguage'] = array_merge($lang_rows['wdlanguage'], (array)$lang_row['wdlanguage']); $lang_rows['expression'] = array_merge($lang_rows['expression'], (array)$lang_row['expression']); $lang_rows['indentical_meaning'] = array_merge($lang_rows['indentical_meaning'], (array)$lang_row['indentical_meaning']);

      } //print_r($arr); return $lang_rows; }

      function get_expression_sub_1($xml, $defined_meaning, $wdlanguage){ $arr = array(); $arr = get_expression_sub_2($arr, $xml, $defined_meaning, $wdlanguage, '1'); $arr = get_expression_sub_2($arr, $xml, $defined_meaning, $wdlanguage, '0'); return $arr; }

      function get_expression_sub_2($arr, $xml, $defined_meaning, $wdlanguage, $indentical_meaning){

      $xpath_expr = '//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]//synonyms-translations[@indentical-meaning="'.$indentical_meaning.'"]/expression[@language="'.$wdlanguage.'"]'; if($defined_meaning->xpath($xpath_expr)){ foreach($defined_meaning->xpath($xpath_expr) as $synonyms_translation){

      $arr['wdlanguage'][] = $wdlanguage; $arr['expression'][] = (string) $synonyms_translation; $arr['indentical_meaning'][] = $indentical_meaning; } } return $arr;

      }


      function build_trainer_link($step, $definedmeaning){ $step = intval($step); $link = wau_lib::build_get_uri_2(); $link = wau_lib::build_get_uri_2('trainer_step', $step, $link); $link = wau_lib::build_get_uri_2('definedmeaning', (string) $definedmeaning, $link);

      if($step == '0'){ $linktext = 'continue with next'; }else{ $linktext = 'show more'; } $link = '<a href="'.$link.'">'.$linktext.'</a>'; return $link; } //synonyms-translations/="1">

      1. /expression language

      ?> </form>

      </body>