Betrete \"$function_name\". Level=$debug_level"; }*/ /* define("PRESENT_TENSE",'PRESENT_TENSE'); define("PAST_TENSE",'PAST_TENSE'); //define("PERFECT_TENSE",'PERFECT_TENSE'); define("PRESENT_PERFECT_TENSE",'PRESENT_PERFECT_TENSE'); define("PAST_PERFECT_TENSE",'PAST_PERFECT_TENSE'); define("CONTNUOUS") */ function mysql_query_2($sql) { GLOBAL $con; deby( "

" . $sql . "

"); $result = mysql_query($sql,$con); deby( mysql_error()); return $result; } /* function process_command($input) { $command = explode(":",$input); if (sizeof($command) == 1) return false; switch ($command[0]) { case $TEXT_VERB: { $sql = "INSERT INTO words"; } } }*/ function output_debug($text) { global $debug; if ($debug) $_SESSION['form'] .= $text; } function output($text) { $_SESSION['form'] .= $text; } function reset_output() { $_SESSION['form'] = ""; } function get_stem_of_verb_third_person($version,$word) { switch ($version) { case 1: if (substr($word,-1)=="s") return substr($word,0,-1); break; case 2: if (substr($word,-2)=="es") { $stem = substr($word,0,-2); $end1 = substr($stem,-1); $end2 = substr($stem,-2); if ($end1=="s" || $end1=="z" || $end1=="x" || $end2=="ch" || $end2=="sh") return $stem; if ($end1=="i" && !is_vocal(substr($end2,0,1))) return substr($stem,0,-1) . "y"; } } return false; } function get_stem_of_verb_past_tense($version,$word) { switch ($version) { case 1: if (substr($word,-2)=="ed") return substr($word,0,-1); break; case 2: if (substr($word,-2)=="ed") { $stem = substr($word,0,-2); $end1 = substr($stem,-1); if ($end1=="i") $stem = substr($stem,0,-1) . "y"; return $stem; } break; case 3: if (substr($word,-2)=="ed") { $stem = substr($word,0,-2); $end1 = substr($stem,-1,1); $end2 = substr($stem,-2,1); $end3 = substr($stem,-3,1); if ($end1==$end2 && !is_vocal($end1) && is_vocal($end3)) if (sizeof($stem)<=8) return substr($stem,0,-1); } } return false; } /* function get_stem_of_verb_past_tense_double_consonant($version,$word) { if (substr($word,-2)=="ed") { $stem = substr($word,0,-2); $end1 = substr($stem,-1,1); $end2 = substr($stem,-2,1); $end3 = substr($stem,-3,1); if ($end1==$end2 && !is_vocal($end1) && is_vocal($end3)) if (sizeof($stem)<=8) return substr($stem,0,-1); } return false; }*/ function get_stem_of_verb_continuous($version,$word) { switch ($version) { case 1: if (substr($word,-3)=="ing") return substr($word,0,-3); break; case 2: if (substr($word,-3)=="ing" && !is_vocal(substr($word,-4,1))) return substr($word,0,-3) . "e"; } return false; } function is_vocal($letter) { return in_array($letter,array('a','e','i','o','u')); } function get_stem_of_noun($version,$word) { switch ($version) { case 2: if (substr($word,-3)=="ves") return substr($word,0,-3) . "f"; case 1: return get_stem_of_verb_third_person($version,$word); } return false; } function get_stem_of_adjective($version,$word) { switch ($version) { case 1: if (substr($word,-2)=="ly") { $stem = substr($word,0,-2); $end1 = substr($stem,-1); if ($end1=='i') $stem = substr($stem,0,-1) . 'y'; return $stem; } break; case 2: if (substr($word,-2)=="ly" && !is_vocal(substr($word,-3,1))) return substr($word,0,-2) . 'le'; break; case 3: if (substr($word,-3)=="lly") return substr($word,0,-1); break; case 4: if (substr($word,-6)=="ically") return substr($word,0,-4); } return false; } function query_word_by_id($word_id) { if ($word_id == 0) return ""; $sql = "SELECT * FROM words WHERE word_id=$word_id"; $result = mysql_query_2($sql); return mysql_fetch_array($result); } function search_word_in_word_table($word,$mask=0,$value=0,$new_type_clear=0,$new_type_set=0) { $sql = "SELECT * FROM words WHERE name='$word' AND (type & $mask)=$value"; $result = mysql_query_2($sql); if ($row = mysql_fetch_array($result)) $row['type'] = ($row['type'] & (~ $new_type_clear)) | $new_type_set; return $row; } function insert_new_word_in_word_table($name,$type,$stem_id=0,$number=0) { if ($stem_id) $sql = "INSERT INTO words (name,type,stem_id,date) VALUES ('$name',$type,'$stem_id',CURRENT_TIMESTAMP)"; else $sql = "INSERT INTO words (name,type,date) VALUES ('$name',$type,CURRENT_TIMESTAMP)"; mysql_query_2($sql); } /* function get_word_id($word) { if ($row = search_word_in_word_table($word)) return $row['word_id']; else return 0; }*/ $VERB_MASK = $WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_infinitive'] | $WORD_TYPE_BIT['verb_irregular']; // | $WORD_TYPE_BIT['verb_double_last_consonant_in_past_tense']; $VERB_STEM = $WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_infinitive']; $standard_conjugation_checking = array( array("versions" => array(1,2), "function" => "get_stem_of_verb_third_person", "mask" => $VERB_MASK, "stem" => $VERB_STEM, "type" => $WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_third_person'], "class_info" => "verb", "stem_info" => "to stem"), array("versions" => array(1,2,3), "function" => "get_stem_of_verb_past_tense", "mask" => $VERB_MASK, "stem" => $VERB_STEM, "type" => $WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_past_tense'] | $WORD_TYPE_BIT['verb_present_perfect_tense'], "class_info" => "verb", "stem_info" => "to stem"), /* array("versions" => array(1), "function" => "get_stem_of_verb_past_tense_double_consonant", "mask" => $VERB_MASK, "stem" => $VERB_STEM, "type" => $WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_past_tense'] | $WORD_TYPE_BIT['verb_double_last_consonant_in_past_tense'], "class_info" => "verb", "stem_info" => "to stem"), */ array("versions" => array(1,2), "function" => "get_stem_of_verb_continuous", "mask" => $VERB_MASK, "stem" => $VERB_STEM, "type" => $WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_continuous'], "class_info" => "verb", "stem_info" => "to stem"), array("versions" => array(1,2), "function" => "get_stem_of_noun", "mask" => $WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['noun_singular'] | $WORD_TYPE_BIT['noun_irregular'] | $WORD_TYPE_BIT['noun_proper'], "stem" => $WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['noun_singular'], "type" => $WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['noun_plural'], "class_info" => "noun", "stem_info" => "the stem"), array("versions" => array(1,2,3,4), "function" => "get_stem_of_adjective", "mask" => $WORD_TYPE_BIT['adjective'] | $WORD_TYPE_BIT['adverb'] | $WORD_TYPE_BIT['adjective_irregular'], "stem" => $WORD_TYPE_BIT['adjective'], "type" => $WORD_TYPE_BIT['adverb'], "class_info" => "adjective", "stem_info" => "a stem thing") ); function get_word($word) { global $WORD_TYPE_BIT,$standard_conjugation_checking; $word_list = array(); //$row = search_word_in_word_table($word); $result = query_word($word); while ($row = mysql_fetch_array($result)) { if ($row['stem_id']) { //$row['stem'] = query_word_by_id($row['stem_id']); $parent = $row; //$type = $row['type']; $row = query_word_by_id($row['stem_id']); $row['type'] = $parent['type']; $row['parent_id'] = $parent['word_id']; $row['parent_name'] = $parent['name']; } $word_list[] = $row; } foreach ($standard_conjugation_checking as $item) { foreach ($item['versions'] as $version) if ($stem = $item['function']($version,$word)) { $row = search_word_in_word_table($stem,$item['mask'],$item['stem'],$item['mask'],$item['type']); if ($row) $word_list[] = $row; } } return $word_list; } /* function prepare_input($input) { $input = trim($input); }*/ /* function radio_button_word($type,$name,$value,$first_column,$second_column,$stem="") { $form .= "$first_column$second_column"; if ($stem != "") $form .= "$stem "; $form .= "
"; return $form; }*/ function radio_buttons_regular_words($name,$word,$class) { global $standard_conjugation_checking; $form = ""; foreach ($standard_conjugation_checking as $item) { if ($item['class_info']==$class) { foreach ($item['versions'] as $version) if ($stem = $item['function']($version,$word)) { $form .= "" . $item['class_info'] . ": " . str_replace("stem",$stem,$item['stem_info']) . ""; /* $form .= radio_button_word("radio",$name,"$stem:" . $item['stem'], $item['class_info'],str_replace("stem",$stem,$item['stem_info'])); */ } } } return $form; } function open_classify_words_form() { return "
"; } function close_classify_words_form() { return "
"; } function radio_buttons_for_classifying_word($word,$input_name) { global $WORD_TYPE_BIT; //$form .= $input_name; $form = "

" . $word . "

"; $form .= ''; $form .= ""; $form .= radio_buttons_regular_words($input_name,$word,"noun"); /* $form .= radio_button_word("radio",$input_name,"$word:" . ($WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['noun_singular']), "noun","the $word") . radio_button_word("radio",$input_name,"$word:" . ($WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['noun_plural']), "noun","many $word","the ") . radio_button_word("radio",$input_name,"$word:" . ($WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['noun_singular'] | $WORD_TYPE_BIT['noun_proper']), "noun","$word"); */ $form .= ""; $form .= radio_buttons_regular_words($input_name,$word,"verb"); /* $form .= radio_button_word("radio",$input_name,"$word:" . ($WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_infinitive'] | $WORD_TYPE_BIT['verb_present_tense']), "verb"," to $word") . radio_button_word("radio",$input_name,"$word:" . ($WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_third_person'] | $WORD_TYPE_BIT['verb_present_tense']), "verb"," it $word","to ") . radio_button_word("radio",$input_name,"$word:" . ($WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_continuous'] | $WORD_TYPE_BIT['verb_present_tense']), "verb continuous"," it is fast $word","to ") . radio_button_word("radio",$input_name,"$word:" . ($WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['verb_third_person'] | $WORD_TYPE_BIT['verb_past_tense']), "verb past tense"," it $word yesterday","to "); */ $mask_verb = ~($WORD_TYPE_BIT['verb_irregular']); // | $WORD_TYPE_BIT['verb_intransitive'] //| $WORD_TYPE_BIT['verb_transitive'] | $WORD_TYPE_BIT['verb_ditransitive']); $form .= ""; /* verb tenses: to it it has
"; */ $form .= radio_buttons_regular_words($input_name,$word,"adjective"); $form .= ""; $form .= ""; //$form .= "
TypeExampleStem
noun: the $word
noun plural: many $word the
noun (proper): $word
verb: to $word
verb: it $word to
verb: $word is to
verb: it $word yesterday to
verb: it has $word to
adjective: a $word thing
adverb: doint it $word a thing
adverb: doing it $word
"; $form .= ""; $form .= "
preposition: of, with
postposition: ago
conjunction: and, but
particle: if, then
question particle: what
modal verb: can, must
relative pronoun: who
article: a, the
pronoun: he, she
synthetical word: _relative_
"; return $form; } function read_words($input) { global $WORD_TYPE_BIT; //echo $input = trim($input); $input = trim($input); $sentence = array(); //$words = preg_split("/[\s,\"]+/",$input); //$words = split_input_into_words($input); /* foreach ($words as $www) echo "#$www# "; die();//"\"$input\""); $words = explode(" ",$input); */ $unknown_words = 0; //false; $position = 0; //foreach ($words as $word) //for ($c=0; $c < sizeof($input); $c++) while (1) { if ($position >= strlen($input)) break; $position = read_white_space($input,$position); // $string_position = $position; list($position,$word) = read_string($input,$position); if ($word != "") enter_word_if_not_exists($word,$WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['noun_proper'] | $WORD_TYPE_BIT['noun_singular'] | $WORD_TYPE_BIT['string']); else list($position,$word) = read_word($input,$position); if (is_numeric($word)) // enter_word_if_not_exists($word,$WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['number'],0,(float) $word); $sentence[] = array('word' => array( array('name' => $word, 'type' => $WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['number']) ), 'raw_word' => $word); else if (is_raw_word_variable($word)) $sentence[] = array('word' => array( array('name' => $word, 'type' => $WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['variable']), array('name' => $word, 'type' => $WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['variable']) ), 'raw_word' => $word); else if ($word != "") { $found_words = get_word($word); if (sizeof($found_words) > 0) { $sentence[] = array('word' => $found_words, 'raw_word' => $word); } else { $sentence[] = 0; if (! $unknown_words) { $form = "There are unknown words. Please classify them according you have used them in your sentence."; $form .= open_classify_words_form(); } $input_name = "word" . $unknown_words++; //$word_counter++; $form .= radio_buttons_for_classifying_word($word,$input_name); } } } if ($unknown_words) { $form .= close_classify_words_form(); return array($unknown_words,$form); } else return array(0,$sentence); //{print_r($sentence); return array(0,$sentence);} } function clear_text_word_type($type) { global $WORD_TYPE_BIT; $text = ""; $bit_list = array('noun','noun_proper','noun_singular','noun_plural','noun_irregular', 'verb','verb_infinitive','verb_third_person','verb_past_tense','verb_present_perfect_tense', 'verb_continuous','verb_irregular','adjective','adverb','adjective_irregular', 'preposition','postposition','conjunction','particle','question_particle', 'modal_verb','relative_pronoun','pronoun','article','synthetical_word','string'); foreach ($bit_list as $bit) if ($type & $WORD_TYPE_BIT[$bit]) $text .= $bit . " + "; return $text; } function print_word_list_open() { return "" . ""; } function print_word_list($word) { return "" . "" . "" . "" . "" . "" . ""; } function print_word_list_close() { return "
idnametypestemdate
" . $word['word_id'] . "" . $word['name'] . "" . clear_text_word_type($word['type']) . "" . $word['stem_id'] . "" . $word['date'] . "
"; } function list_word(&$sentence,$position) { //$text = "

" . $sentence[$position]['raw_word'] . "

"; $text = print_word_list_open(); foreach ($sentence[$position]['word'] as $word) $text .= print_word_list($word); return $text . print_word_list_close(); } function print_word_of_word_table($word) { $result = query_word($word); $text = print_word_list_open(); while ($row = mysql_fetch_array($result)) { $text .= print_word_list($row); } return $text . print_word_list_close(); } //$last_selected_word_id = 0; function word_type_checking(&$word_list,$flag,$mark_word=false) { //foreach ($word_list as $word) for ($c=0; $c < sizeof($word_list); $c++) { if ($word_list[$c]['type'] & $flag) { if ($mark_word) $word_list[$c]['selected'] = true; return true; } } return false; } function word_name_checking(&$word_list,$names,$mark_word=false) { for ($c=0; $c < sizeof($word_list); $c++) { if (in_array($word_list[$c]['name'],$names)) { if ($mark_word) $word_list[$c]['selected'] = true; return true; } } return false; } function is_preposition(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['preposition'],$mark_word); } function is_particle(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['particle'],$mark_word); } function is_noun(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['noun'],$mark_word); } function is_verb(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['verb'],$mark_word); } function is_verb_continuous(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['verb_continuous'],$mark_word); } function is_verb_perfect_tense(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['verb_present_perfect_tense'],$mark_word); } function is_verb_past_tense(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['verb_past_tense'],$mark_word); } function is_verb_infinitive(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['verb_infinitive'],$mark_word); } function is_modal_verb(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['modal_verb'],$mark_word); } function is_relative_pronoun(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['relative_pronoun'],$mark_word); } function is_conjunction(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['conjunction'],$mark_word); } function is_question_particle(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['question_particle'],$mark_word); } function is_adjective(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['adjective'],$mark_word); } function is_adverb(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['adverb'],$mark_word); } function is_article(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['article'],$mark_word); } function is_synthetical_word(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['synthetical_word'],$mark_word); } /* function is_article(&$word_list,$mark_word=false) { return word_name_checking($word_list,array(WORD_A,WORD_AN,WORD_THE),$mark_word); }*/ function is_number(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['number'],$mark_word); } function is_variable(&$word_list,$mark_word=false) { global $WORD_TYPE_BIT; return word_type_checking($word_list,$WORD_TYPE_BIT['variable'],$mark_word); } function is_do(&$word_list,$mark_word=false) { global $WORD; return word_name_checking($word_list,array(WORD_DO),$mark_word); // return word_name_checking($word_list,array(WORD_DO,WORD_DOES,WORD_DID),$mark_word); } function is_auxiliary_verb(&$word_list,$mark_word=false) { return word_name_checking($word_list,array(WORD_HAVE,WORD_BE,WORD_DO),$mark_word); } function is_have(&$word_list,$mark_word=false) { global $WORD; return word_name_checking($word_list,array(WORD_HAVE),$mark_word); // return word_name_checking($word_list,array(WORD_HAVE,WORD_HAS,WORD_HAD),$mark_word); } function is_be(&$word_list,$mark_word=false) { global $WORD; return word_name_checking($word_list,array(WORD_BE),$mark_word); //return word_name_checking($word_list,array(WORD_IS,WORD_BE,WORD_BEEN,WORD_BEING),$mark_word); } function is_will(&$word_list,$mark_word=false) { global $WORD; return word_name_checking($word_list,array(WORD_WILL),$mark_word); //return word_name_checking($word_list,array(WORD_IS,WORD_BE,WORD_BEEN,WORD_BEING),$mark_word); } function is_would(&$word_list,$mark_word=false) { global $WORD; return word_name_checking($word_list,array(WORD_WOULD),$mark_word); //return word_name_checking($word_list,array(WORD_IS,WORD_BE,WORD_BEEN,WORD_BEING),$mark_word); } function is_and(&$word_list,$mark_word=false) { global $WORD; return word_name_checking($word_list,array(WORD_AND),$mark_word); } function is_pullstop(&$word_list,$mark_word=false) { global $WORD; return word_name_checking($word_list,array(CHAR_POINT),$mark_word); } function is_verb_selected(&$sentence,$position) { global $WORD_TYPE_BIT; $word = get_selected_word($sentence[$position]['word']); return $word['type'] & $WORD_TYPE_BIT['verb']; } function is_string_selected(&$sentence,$position) { global $WORD_TYPE_BIT; $word = get_selected_word($sentence[$position]['word']); return $word['type'] & $WORD_TYPE_BIT['string']; } function is_general_noun_selected(&$sentence,$position) { global $WORD_TYPE_BIT; $word = get_selected_word($sentence[$position]['word']); return ($word['type'] & ($WORD_TYPE_BIT['noun'] | $WORD_TYPE_BIT['noun_proper'])) == $WORD_TYPE_BIT['noun']; } function is_preposition_selected(&$sentence,$position) { global $WORD_TYPE_BIT; $word = get_selected_word($sentence[$position]['word']); return $word['type'] & $WORD_TYPE_BIT['preposition']; } function is_noun_or_gerund_selected(&$sentence,$position) { global $WORD_TYPE_BIT; $word = get_selected_word($sentence[$position]['word']); return ($word['type'] & $WORD_TYPE_BIT['noun']) || isset($sentence[$position]['gerund']); } function is_noun_selected(&$sentence,$position) { global $WORD_TYPE_BIT; $word = get_selected_word($sentence[$position]['word']); return ($word['type'] & $WORD_TYPE_BIT['noun']); } function get_tense_selected_word(&$word_list) { global $WORD_TYPE_BIT; $word = get_selected_word($word_list); // if ($word['type'] & $WORD_TYPE_BIT['verb_infinitive'] || $word['type'] & $WORD_TYPE_BIT['verb_third_person']) // return 'present'; /* function get_tense($word) {*/ if ($word['type'] & $WORD_TYPE_BIT['verb_past_tense']) return 'past'; if ($word['type'] & $WORD_TYPE_BIT['verb_present_perfect_tense']) return 'perfect'; return 'present'; } /* function unselect_word(&$sentence,$position) { for ($c=0; $c < sizeof($sentence[$position]['word']); $c++) unset($sentence[$position]['word'][$c]['selected']); } function get_word_id_depending_on_type(&$sentence,$position,$flag) { $word_list = $sentence[$position]['word']; for ($c=0; $c < sizeof($word_list); $c++) if ($word_list[$c]['type'] & $flag) return $word_list[$c]['word_id']; } function get_verb_word_id(&$sentence,$position) { global $WORD_TYPE_BIT; return get_word_id_depending_on_type($sentence,$position,$WORD_TYPE_BIT['verb']); } function get_verb_word_id(&$sentence,$position) { global $WORD_TYPE_BIT; return get_word_id_depending_on_type($sentence,$position,$WORD_TYPE_BIT['verb']); } */ /* function is_selected_verb_continuous(&$word_list) { global $WORD_TYPE_BIT; $word = get_selected_word($word_list); return $word['type'] & $WORD_TYPE_BIT['verb_continuous']; } */ /* function is_selected_verb_perfect_tense(&$word_list) { global $WORD_TYPE_BIT; $word = get_selected_word($word_list); return $word['type'] & $WORD_TYPE_BIT['verb_present_perfect_tense']; }*/ function is_selected_verb_infinitive(&$word_list) { global $WORD_TYPE_BIT; $word = get_selected_word($word_list); return $word['type'] & $WORD_TYPE_BIT['verb_infinitive']; } function get_child(&$sentence,$position,$l_type,$raw_word=false) { //echo print_sentence_detailed($sentence); for ($c=0; $c < sizeof($sentence); $c++) { if (isset($sentence[$c]['l_value'])) if ($sentence[$c]['l_value']==$position && $sentence[$c]['l_type']==$l_type) if ($raw_word) { if ($sentence[$c]['raw_word']==$raw_word) return $c; } else return $c; } return INVALID_POSITION; } function get_referring_child(&$sentence,$position) { for ($c=0; $c < sizeof($sentence); $c++) { if (isset($sentence[$c]['l_value']) && isset($sentence[$c]['reference']) && $sentence[$c]['l_value']==$position) return $sentence[$c]['reference']; } return INVALID_POSITION; } function get_reference_child(&$sentence,$position) { for ($c=0; $c < sizeof($sentence); $c++) if (isset($sentence[$c]['l_value']) && isset($sentence[$c]['reference'])) if ($sentence[$c]['l_value'] == $position) return $sentence[$c]['reference']; return INVALID_POSITION; } /* function get_child_including_reference(&$sentence,$position,$l_type) { //echo print_sentence_detailed($sentence); for ($c=0; $c < sizeof($sentence); $c++) { if (isset($sentence[$c]['l_value'])) if ($sentence[$c]['l_value']==$position && $sentence[$c]['l_type']==$l_type) return $c; if ($sentence[$c]['raw_word']==SYNTHETICAL_WORD_REFERENCE && ) } return INVALID_POSITION; } */ /* function is_verb_relative(&$sentence,$position) { if (get_child($sentence,$position,L_TYPE,SYNTHETICAL_WORD__RELATIVE_L_VALUE) == INVALID_POSITION) return false; else return true; }*/ /* function decode_input($word) { if ($word[$word_position]['type']==$WORD_TYPE_NOUN) $sentence_status[$sentence_level] = "await subject"; switch ($current_word_type) { case "noun": { $subject[$sentence_level][] = $current_word; $subject[$sentence_level][] } }*/ /*class sentence { */ /* public function make_brackets($sentence,$decision_sequence) { $sentence_clause = "ad_verb_1"; //$sentence_sub_part = "1"; $begin_read_clause $output[] = "("; $output[] = $sentence_part; $clause = ")"; } */ /* protected function read_adverbial_clause() { if ($input[$input_pos]['type'] == $WORD_TYPE_PREPOSITION) { $output[$output_pos++] = $BRACKET_OPEN; $output[$output_pos++] = $input[$input_pos++]; read_object_clause(); $output[$output_pos++] = $BRACKET_CLOSE; return true; } else return false } */ /* function read_adverbial_clause($sentence,$position) { if (isset($sentence[$position]) && $sentence[$position]['type'] == $WORD_TYPE['preposition']) { $position = read_object_clause($sentence,$position) } }*/ /* function seek_object_clause($sentence,$position) { if (isset($sentence[$position])) { if ($sentence[$position]['type'] == $WORD_TYPE['preposition']) { $position = read_object_clause($sentence,$position); } } } function get_clause($sentence,$position) { } */ /* function skim_adverbial_clause(&$sentence,$position,$size="max") { //global $WORD_TYPE; $position_start = $position; $error = false; while (1) { if (isset($sentence[$position])) { if (is_preposition($sentence[$position]['word'])) //($sentence[$position]['type'] == $WORD_TYPE['preposition']) { //position_interval = read_preposition_clause($sentence,$position,"min"); list($error,$pos,$anchor) = skim_object_clause($sentence,++$position,"min"); if ($error) break; //return array(false,$position_start,$position); $position = $pos; if ($size=="min") break; } else break; } else break; } if ($position_start==$position) $error = 'empty'; return array($error,$position); //array_slice($sentence,$position_start,$position)); } */ /* function skim_object_clause(&$sentence,$position,$level,$expect_noun=false,$size="max") { $sentence_2 = $sentence; return analyse_object_clause($sentence_2,$position,$level,$expect_noun,true,false); }*/ /* function skim_object_clause(&$sentence,$position,$size="max") { //global $WORD_TYPE; echo $position_start = $position; $error = false; while (1) { if (isset($sentence[$position])) { //$type = $sentence[$position]['type']; //if ($type == $WORD_TYPE['noun'] || $type == $WORD_TYPE['noun_plural'] || $type == $WORD_TYPE['noun_proper']) //$current_word = $sentence[$position]['word']; //if (is_noun($current_word) || is_adjective($current_word) || is_adverb($current_word)) list($error,$position) = skim_noun($sentence,$position); if (!$error) { //$position++; echo " -new pos after noun = " . $position; if ($size=="min") break; if (isset($sentence[$position]) && is_preposition($sentence[$position]['word'])) //$sentence[$position]['type'] == $WORD_TYPE['preposition']) { //list ($error,$pos) = skim_object_clause($sentence,++$position,$size); // //list ($error,$pos) = skim_adverb_clause($sentence,$position,$size); $position++; echo "mhm " . $error; if ($error) break; //echo "--" . $position = $pos; } else break; } else break; } else break; } if (!$error && $position_start==$position) echo $error = 'empty'; return array($error,$position); } */ function skim_verb_clause(&$sentence,$position,$question_verb=INVALID_POSITION) { $sentence_2 = $sentence; return analyse_verb_clause($sentence,$position,$question_verb,true); } function analyse_verb_clause(&$sentence,$position,$question_verb=INVALID_POSITION,$skim_mode=false,$l_value=INVALID_POSITION,$l_type=L_TYPE) { while (1) { list($error,$position,$anchor_verb,$gerund) = analyse_one_verb_clause($sentence,$position,$question_verb,$l_value,$l_type); break; // absichtlich kein "and" bei verb!! if ($error) break; $l_value = $position; list($error_and,$position) = analyse_and($sentence,$position,$anchor_verb,$skim_mode); if ($error_and) break; list($error,$position,$second_anchor_verb,$second_gerund) = analyse_verb_clause($sentence,$position,$question_verb,$skim_mode,$l_value,$l_type); break; } return array($error,$position,$anchor_verb,$gerund); } function analyse_one_verb_clause(&$sentence,$position,$question_verb=INVALID_POSITION,$l_value=INVALID_POSITION,$l_type=L_TYPE) { //global $WORD_TYPE; deby("
starte Verb analyse an position=$position, question_verb = $question_verb"); $position_start = $position; $error = false; // $precursory_adverb = false; $modal_verb = false; $anchor_verb = INVALID_POSITION; $last_verb = INVALID_POSITION; $gerund = false; //$time = 0; $do = false; $did = false; $will = false; $have = false; $had = false; $be = false; $second_be = false; //$question_verb_used = false; if ($question_verb != INVALID_POSITION) { is_verb($sentence[$question_verb]['word'],true); is_modal_verb($sentence[$question_verb]['word'],true); } while (isset_primary_sentence_position($sentence,$position)) { list($error_adverb,$position) = skim_adverb($sentence,$position); if (is_verb($sentence[$position]['word'],true) || is_modal_verb($sentence[$position]['word'],true)) { $current_word = $sentence[$position]['word']; if ($last_verb == INVALID_POSITION && is_verb_continuous($current_word)) {$gerund = true; deby( "
yes gerund!");} else deby( "
kein gerund bei $position!"); $last_verb = $position; if ( !( is_modal_verb($current_word) || is_have($current_word) || is_be($current_word) || is_do($current_word) || is_will($current_word) || is_would($current_word)) ) { deby( "#habe anchor verb "); $anchor_verb = $position; break; } else $position++; } else break; } if ($anchor_verb == INVALID_POSITION) $anchor_verb = $last_verb; deby("
anchor verb in verb analyse = $anchor_verb"); //if ($anchor_verb==INVALID_POSITION && $question_verb != INVALID_POSITION ) $last_verb = INVALID_POSITION; $position = $position_start; if ($anchor_verb != INVALID_POSITION) { while (1) { if ($question_verb != INVALID_POSITION) { $position = $question_verb; //is_verb($sentence[$position]['word'],true); } if ($position != $anchor_verb) list ($error_adverb,$position) = analyse_adverb($sentence,$position,$anchor_verb); $current_word = $sentence[$position]['word']; $selected_word = get_selected_word($current_word); $word = $selected_word['name']; $raw_word = $sentence[$position]['raw_word']; if ($position != $anchor_verb) { // echo "
last verb =$last_verb, question verb = $question_verb, position= $position"; if ($word==WORD_DO) { if ($last_verb != INVALID_POSITION) throw new sentence_exception("invalid 'do'",$position_start,$position); $do = $word; $do_position = $position; if ($raw_word==WORD_DID) //$did = $word; $sentence[$anchor_verb]['did'] = true; } else //if (is_will($current_word) || is_would($current_word)) if ($word==WORD_WILL || $word==WORD_WOULD) { if ($last_verb != INVALID_POSITION) throw new sentence_exception("invalid 'will' or 'would'",$position_start,$position); // throw new sentence_exception("double 'will' or 'would'",$position_start,$position); /* if (is_will($current_word)) $will = true; else $would = true;*/ $will = $word; if ($word==WORD_WILL) $sentence[$anchor_verb]['will'] = true; else $sentence[$anchor_verb]['would'] = true; } else if ($word==WORD_HAVE) { if ($have || $be || $do) throw new sentence_exception("invalid 'have'",$position_start,$position); /* $tense_of_have = get_tense_selected_word($current_word); if ($will && !is_selected_verb_infinitive($current_word)) throw new sentence_exception("invalid tense of 'have'",$position_start,$position); */ if ($raw_word == WORD_HAD) { //$had = true; $sentence[$anchor_verb]['had'] = true; if ($will) throw new sentence_exception("invalid '$raw_word'",$position_start,$position); } else $sentence[$anchor_verb]['have'] = true; $have = $word; //replace_selected_stem_word_by_parent_word($sentence[$position]['word']); } else if ($word==WORD_BE) { if ($do) throw new sentence_exception("invalid 'be'",$position_start,$position); if ($be) { if (is_verb_continuous($current_word) && !$second_be) { $second_be = $word; $second_be_position = $position; } else throw new sentence_exception("invalid 'be'",$position_start,$position); } else { if (($have && $raw_word != WORD_BEEN) || ($will && $raw_word != WORD_BE)) throw new sentence_exception("invalid '$raw_word'",$position_start,$position); //$tense_of_be = get_tense_selected_word($current_word); $be = $word; $be_position = $position; } } else if (is_modal_verb($current_word)) { if ($modal_verb) throw new sentence_exception("too many modal verbs",$position_start,$position); $modal_verb = true; $sentence[$anchor_verb]['modal_verb'] = true; $sentence[$position]['l_value'] = $anchor_verb; $sentence[$position]['l_type'] = L_TYPE; } $last_verb = $position; if (!isset($sentence[$position]['l_value'])) set_l_value_drop($sentence[$position]); //$sentence[$position]['l_value'] = $anchor_verb; //$sentence[$position]['l_type'] = L_TYPE; if ($question_verb != INVALID_POSITION) { $question_verb = INVALID_POSITION; $position = $position_start; } else $position++; } else break; } //$tense_anchor_verb = get_tense($selected_word); //$tense_anchor_verb = get_tense_selected_word($current_word); if ($be) { if (!$second_be) { if (is_verb_perfect_tense($current_word)) { $sentence[$anchor_verb]['passive'] = true; //set_l_value_drop($sentence[$be_position]); //$sentence[$be_position]['l_type'] = PASSIVE_TYPE; } else if (is_verb_continuous($current_word)) //$sentence[$be_position]['l_type'] = CONTINUOUS_TYPE; $sentence[$anchor_verb]['continuous'] = true; else throw new sentence_exception("expected progressive or perfect form",$position_start,$position); } else { //$sentence[$be_position]['l_type'] = CONTINUOUS_TYPE; //$sentence[$second_be_position]['l_type'] = PASSIVE_TYPE; $sentence[$anchor_verb]['continuous'] = true; $sentence[$anchor_verb]['passive'] = true; if (!is_verb_perfect_tense($current_word)) throw new sentence_exception("expected perfect form",$position_start,$position); } } else if ($have) { if (!is_verb_perfect_tense($current_word)) throw new sentence_exception("expected perfect tense",$position_start,$position); // if ($have==WORD_HAD) } else if ($will || $modal_verb) { if (!is_verb_infinitive($current_word)) throw new sentence_exception("expected infinitive",$position_start,$position); } else if (!$do) //(!($will || $do || $modal_verb)) if (is_verb_past_tense($current_word)) $did = true; if ($did) $sentence[$anchor_verb]['did'] = true; //else //if ($do) // set_l_value_drop($sentence[$do_position]); /* while (1) { if ($position != $anchor_verb) list ($error_adverb,$position) = analyse_adverb($sentence,$position,$anchor_verb); if ($position != $anchor_verb) { set_l_value_end($sentence[$position]); $position++; } else break; } */ $position = $anchor_verb+1; /* $position_last_verb_continuous = INVALID_POSITION; list($error_adjective,$pos) = skim_adjective($sentence,$position,$position_last_verb_continuous); if ($error_adjective == 'empty') list($error_adverb,$position) = analyse_adverb($sentence,$position,$anchor_verb); */ } else { /*if ($question_verb != INVALID_POSITION) { $anchor_verb = $question_verb; //is_verb($sentence[$question_verb]['word'],true); if (!(is_be($sentence[$question_verb]['word']))) || is_have($sentence[$question_verb]['word'])))) throw new sentence_exception('invalid position of verb',$position_start,$position); } else*/ { if ($position_start == $position) $error = 'empty'; else throw new sentence_exception('missing (main) verb',$position_start,$position); } } // $error = true; list($error_adverb,$end_pos_adverb) = skim_adverb($sentence,$position); if ($error_adverb != 'empty') { if (! (isset_primary_sentence_position($sentence,$end_pos_adverb) && (is_adjective($sentence[$end_pos_adverb]['word']) || is_verb($sentence[$end_pos_adverb]['word'])) )) list($error_adverb,$position) = analyse_adverb($sentence,$position,$anchor_verb); } //if ($gerund) // $sentence[$anchor_verb]['gerund'] = true; /* list($error_adverb,$position) = skim_adverb($sentence,$position); if (isset($sentence[$position]) && is_verb($sentence[$position]['word'],true)) { $anchor_verb = $position; $position++; analyse_adverb($sentence,$position_start,$anchor_verb); $position_last_verb_continuous = INVALID_POSITION; list($error_adjective,$pos) = skim_adjective($sentence,$position,$position_last_verb_continuous); if ($error_adjective == 'empty') list($error_adverb,$position) = analyse_adverb($sentence,$position,$anchor_verb); } else $position = $position_start; */ /*test_error_empty($error,$position,$position_start); if ($error && $error != 'empty') throw new sentence_excpetion('missing verb',$position_start,$position); */ if ($anchor_verb != INVALID_POSITION) { $sentence[$anchor_verb]['l_value'] = $l_value; $sentence[$anchor_verb]['l_type'] = $l_type; } return array($error,$position,$anchor_verb,$gerund); } /* function analyse_verb_clause(&$sentence,$position) { //global $WORD_TYPE; $position_start = $position; $error = false; $precursory_adverb = false; $modal_verb = false; $anchor_verb = INVALID_POSITION; while (1) { if (isset($sentence[$position])) { if ($anchor_verb == INVALID_POSITION && is_verb($sentence[$position]['word'],true)) { set_precursory_adverb($sentence,$precursory_adverb,$position); $anchor_verb = $position; $position++; $c = $position; while (1) { if (isset($sentence[$c]) && is_adverb($sentence[$c]['word'])) $c++; else break; } if (isset($sentence[$c]) && is_adjective($sentence[$c]['word'])) break; } else if (is_adverb($sentence[$position]['word'],true)) { set_precursory_adverb($sentence,$precursory_adverb,$position); $precursory_adverb = true; echo "adverbpos " . $position++; } else { if ($anchor_verb == INVALID_POSITION) $error = true; break; } } else break; } set_precursory_adverb($sentence,$precursory_adverb,$position,$anchor_verb); if (!$error && $position_start==$position) $error = 'empty'; return array($error,$position,$anchor_verb); } */ /* function read_object_clause($sentence,$position) { //global $sentence,$position; global $WORD_TYPE,$BRACKET_OPEN,$BRACKET_CLOSE; if (isset($sentence[$position]) && $sentence[$position]['type'] == $WORD_TYPE['noun']) { $output[] = $BRACKET_OPEN; $output[] = $sentence[$position++]; if (isset($sentence[$position]) && $sentence[$position]['type'] == $WORD_TYPE['preposition']) { if (get_decision()) { $output[] = $BRACKET_CLOSE; return $output; } else { //$output[$output_pos++] = $BRACKET_CLOSE; $output[] = $sentence[$position++]; $next_object = read_object_clause($sentence,$position); return array_merge($output,$next_object,$BRACKET_CLOSE); } } else { $output[] = $BRACKET_CLOSE; return $output; } } else return array(); } */ /* function get_decision() { global $decision_sequence,$decision_depth; $bit = $decision_sequence & 1; $decision_sequence >> 1; $decision_depth++; return $bit; } */ function set_l_value_end(&$word_in_sentence) { save_l_value($word_in_sentence); $word_in_sentence['l_value'] = L_VALUE_END; $word_in_sentence['l_type'] = L_TYPE_END; } function save_l_value(&$word_in_sentence) { if (isset($word_in_sentence['l_value'])) $word_in_sentence['former_l_value'] = $word_in_sentence['l_value']; } function set_l_value_drop(&$word_in_sentence /*,$overwrite_l_value=true*/) { save_l_value($word_in_sentence); //if ($overwrite_l_value) $word_in_sentence['l_value'] = L_VALUE_END; $word_in_sentence['l_type'] = L_TYPE_DROP; } /* function set_l_value_unknown(&$word_in_sentence) { $word_in_sentence['l_value'] = L_VALUE_END; $word_in_sentence['l_type'] = L_TYPE_UNKNOWN; }*/ class sentence_exception extends Exception { public $error; public $position_start; public $position; public function __construct($error='error',$position_start=0,$position=0) { $this->error = $error; $this->position_start = $position_start; $this->position = $position; parent::__construct($error,0); } public function print_error() { $text = "

error = " . $this->error . " in positions " . $this->position_start . " - " . $this->position . "

"; return $text; } } function analyse_sentence(&$sentence,$mode) { try { if (sizeof($sentence)==1 && $mode=='enter') { $error = glossary_maintenance($sentence); } else { if ($mode=='search') { if (false && check_for_question($sentence)) { list($error,$position,$anchor_verb,$gerund,$anchor_subject) = analyse_question($sentence); //$task = "answer"; } else { list($error,$position,$anchor_verb,$gerund,$anchor_subject) = analyse_assertion($sentence,0,0,false,false,INVALID_POSITION, false,true,INVALID_POSITION,true,INVALID_POSITION,false,true); } if (isset_primary_sentence_position($sentence,$position)) throw new sentence_exception('invalid extra words',0,$position); $save_sentence = $sentence; if (!$error) { print_decisions($sentence); output(answer_question($save_sentence)); } //refresh_statistics($sentence); } else { list($error,$position) //,$anchor_verb,$gerund,$anchor_subject) = analyse_input($sentence,0,0,false,false,INVALID_POSITION,false,true); //$task = "enter"; if (isset_primary_sentence_position($sentence,$position)) throw new sentence_exception('invalid extra words',0,$position); $save_sentence = $sentence; if (!$error) { //if ($mode=='enter') enter_sentence($save_sentence); refresh_statistics($save_sentence); print_decisions($sentence); } } //if (DEBUG_MODE) output_debug(print_sentence_detailed($save_sentence)); //if ($position < sizeof($sentence)) // if ($error=='decision') // output(print_sentence_alternatives($sentence)); /* if (!$error) { $text = "
Click highlighted parts for correcting wrong connections:
"; //$primary_sentence = get_primary_sentence($sentence); $text .= "

" . print_sentence_highlight_decided($sentence) . "

"; output($text); }*/ } } catch (sentence_exception $exception) { /* if ($exception->error=='decision') { deby(print_sentence_detailed($sentence)); //delete_synthetical_words($sentence); output("
Choose what you are meaning:
"); $primary_sentence = get_primary_sentence($sentence); output(print_sentence_alternatives($primary_sentence)); } elseif ($exception->error=='decision verb') { //delete_synthetical_words($sentence); output("
Choose what you are meaning:
"); $primary_sentence = get_primary_sentence($sentence); output(print_sentence_alternatives_verb($primary_sentence)); } else { output($exception->print_error()); output_debug(print_sentence_detailed($sentence)); } // if ($exception->error=='decision_noun') // output(print_sentence_alternatives_noun($sentence)); */ deby( $exception->print_error()); deby(print_sentence_detailed($sentence)); if (substr($exception->error,0,8) != 'decision') output( $exception->print_error()); else { //$sentence = $save_sentence; reset_sentence_for_reprocessing($sentence); } return array($exception->error); } //reset_sentence_for_reprocessing($sentence); return array($error); } function check_for_question(&$sentence,$position=0) { //if (is_question_particle($sentence[0]['word'],true)) if ( (is_auxiliary_verb($sentence[$position]['word']) || is_modal_verb($sentence[$position]['word'])) && !is_verb_continuous($sentence[$position]['word']) || is_question_particle($sentence[$position]['word']) ) { // set_l_value_end($sentence[0]); return true; } else return false; } function analyse_question(&$sentence) { if (is_question_particle($sentence[0]['word'],true)) { set_l_value_drop($sentence[0]); $first_word = $sentence[0]['raw_word']; //get_selected_word($sentence[0]['word']); if ($first_word==WORD_WHO || $first_word==WORD_WHAT) // || $first_word==WORD_WHICH) { //echo "
subjektfrage"; if (check_for_question($sentence,1)) return analyse_assertion($sentence,1,0,false,false,INVALID_POSITION,false,true,1,true); else return analyse_assertion($sentence,1,0,false,false,INVALID_POSITION,true,true,INVALID_POSITION); } } else return analyse_assertion($sentence,0,0,false,false,INVALID_POSITION,false,true,0); // analyse_assertion(&$sentence,$position=0,$skim_mode=false,$anchor_subject=INVALID_POSITION,$no_subject_mode=false /* no_subject_mode */ // ,$change_passive_to_active=false,$question_verb=INVALID_POSITION,$allow_overwrite_subject=false) //{ /* if (is_do($sentence[0]['word'])) { return analyse_assertion($sentence,1); } */ } function skim_assertion(&$sentence,$position=0,$level=0,$expect_noun=false,$anchor_subject=INVALID_POSITION,$no_subject_mode=false,$change_passive_to_active=false, $question_verb=INVALID_POSITION,$allow_overwrite_subject=false) { $sentence_2 = $sentence; return analyse_assertion($sentence_2,$position,$level,$expect_noun,true,$anchor_subject,$no_subject_mode,$change_passive_to_active,$question_verb,$allow_overwrite_subject); } /* function skim_or_analyse_assertion(&$sentence,$position,$skim_mode,$anchor_subject,$no_subject_mode=false,$change_passive_to_active=false, $question_verb=INVALID_POSITION,$allow_overwrite_subject=false) { if ($skim_mode) return skim_assertion($sentence,$position,$anchor_subject,$no_subject_mode,$change_passive_to_active,$question_verb,$allow_overwrite_subject); else return analyse_assertion($sentence,$position,false,$anchor_subject,$no_subject_mode,$change_passive_to_active,$question_verb,$allow_overwrite_subject); }*/ function analyse_input(&$sentence,$position=0,$level=0,$expect_noun=false,$skim_mode=false,$anchor_subject=INVALID_POSITION,$no_subject_mode=false /* no_subject_mode */ ,$change_passive_to_active=false,$question_verb=INVALID_POSITION,$allow_overwrite_subject=false, $anchor_verb_of_expecting_noun=INVALID_POSITION,$relative=false,$phrase_mode=false,$l_value=INVALID_POSITION) { while (1) { list($error,$position,$anchor_verb,$gerund,$returned_anchor_subject) = analyse_assertion($sentence,$position,$level,$expect_noun,$skim_mode,$anchor_subject,$no_subject_mode, $change_passive_to_active,$question_verb,$allow_overwrite_subject, $anchor_verb_of_expecting_noun,$relative,$phrase_mode,$l_value); if ($error) break; list($error_pullstop,$position) = analyse_pullstop($sentence,$position); if ($error_pullstop) break; if (!isset_primary_sentence_position($sentence,$position)) break; } return array($error,$position); } function analyse_assertion(&$sentence,$position=0,$level=0,$expect_noun=false,$skim_mode=false,$anchor_subject=INVALID_POSITION,$no_subject_mode=false /* no_subject_mode */ ,$change_passive_to_active=false,$question_verb=INVALID_POSITION,$allow_overwrite_subject=false, $anchor_verb_of_expecting_noun=INVALID_POSITION,$relative=false,$phrase_mode=false,$l_value=INVALID_POSITION) { while (1) { list($error,$position,$anchor_verb,$gerund,$returned_anchor_subject) = analyse_one_assertion($sentence,$position,$level,$expect_noun,$skim_mode,$anchor_subject,$no_subject_mode, $change_passive_to_active,$question_verb,$allow_overwrite_subject, $anchor_verb_of_expecting_noun,$relative,$phrase_mode,$l_value); if ($error) break; //deby("
nach analyse one assertion: " . print_sentence_detailed($sentence)); $l_value = $position; list($error_and,$position) = analyse_and($sentence,$position,$anchor_verb,$skim_mode); if ($error_and) break; if ($level==0) { $anchor_subject = $returned_anchor_subject; $allow_overwrite_subject = true; } list($error,$position,$second_anchor_verb,$second_gerund,$second_returned_anchor_subject) = analyse_assertion($sentence,$position,$level,$expect_noun,$skim_mode,$anchor_subject,$no_subject_mode, $change_passive_to_active,$question_verb,$allow_overwrite_subject, $anchor_verb_of_expecting_noun,$relative,$phrase_mode,$l_value); break; } return array($error,$position,$anchor_verb,$gerund,$returned_anchor_subject); } function analyse_one_assertion(&$sentence,$position=0,$level=0,$expect_noun=false,$skim_mode=false,$anchor_subject=INVALID_POSITION,$no_subject_mode=false /* no_subject_mode */ ,$change_passive_to_active=false,$question_verb=INVALID_POSITION,$allow_overwrite_subject=false, $anchor_verb_of_expecting_noun=INVALID_POSITION,$relative=false,$phrase_mode=false, $l_value=INVALID_POSITION) { //global $sentence,$position; // global $decision_sequence,$decision_depth; // $decsion_depth = 0; // $decision_sequence = 6; //$input = array(); //$output = array(); //$input_pos = 0; //$output_pos = 0; // $position = 0; //clauses = array("read_adverbial_clause","read_object_clause","read_verb_clause","read_object_clause",""read_adverbial_clause"); /* list($error,$adverbial_clause_1) = read_adverbial_clause($sentence,$position,"max"); if (!$error) { $ } */ //list($error,$clause) = read_ad_clause($sentence,0,$size); deby( "
**analyse_assertion** -- skim_mode = $skim_mode, anchor subject = $anchor_subject, expect_noun=$expect_noun"); if ($question_verb != INVALID_POSITION) $position++; $extern_anchor_subject = $anchor_subject; $sentence_2 = $sentence; $sentence_3 = $sentence; deby(print_sentence_detailed($sentence)); $position_subject = $position; while (1) { list($error,$position_subject) = analyse_adverbial_clause($sentence_3,$position_subject,$level,true,true,false, INVALID_POSITION,$position_subject,INVALID_POSITION,false); // skim_adverbial_clause($sentence,$position,true,"max"); deby ("
first adverbial clause analyse: error= $error, new pos = $position_subject"); if ($error == 'empty') break; } deby( "
position subject nach adverbial clause analyse = $position_subject"); //if (!$error) // $all_clauses[] = array_slice($sentence,0,$position_subject); // if ($error && $error != 'empty') return array($error,$position_subject); //$position_verb = $position_subject; //echo "
$anchor_subject, $allow_overwrite_subject," . !$no_subject_mode; $error_subject = 'empty'; if (($anchor_subject==INVALID_POSITION || $allow_overwrite_subject) && !$no_subject_mode) { list($error_subject,$position_verb,$anchor) = analyse_there($sentence_2,$position_subject); if ($error_subject) { deby("
Skime subjekt an $position_subject"); list($error_subject,$position_verb,$anchor) = analyse_object_clause($sentence_2,$position_subject,$level,false,true /*true*/,false, L_VALUE_END,$position_subject,L_TYPE_END,L_VALUE_END,true,false,true); // skim_object_clause($sentence,$position_subject,false,"max"); //echo "
error subject = $error_subject, $position_subject, $position_verb"; die(); //if ($error) return array($error,$position_verb); if ($error_subject) if ($allow_overwrite_subject) // && $anchor_subject != INVALID_POSITION) $position_verb = $position_subject; else { deby(print_sentence_detailed($sentence_3)); throw new sentence_exception('missing subject',$position,$position_verb); } } } else $position_verb = $position_subject; deby( "
position verb = $position_verb"); // $all_clauses[] = array_slice($sentence,$position_subject,$position_verb-$position_subject); list($error,$position_first_object,$anchor_verb,$gerund) = skim_verb_clause($sentence,$position_verb,$question_verb); if ($error) { // //if (($position_verb = max_position($last_passive_participle_adverbial_clause,$last_passive_participle_subject)) == INVALID_POSITION) //$position_verb = get_last_passive_participle($sentence_2,$position_verb); //deby("danach position verb = " . $position_verb); // //if (($position_verb) == INVALID_POSITION) { //deby(print_sentence_detailed($sentence_2)); if (sizeof(get_all_passive_participles($sentence_2))==0) { if (!$phrase_mode) throw new sentence_exception('missing verb',$position,$position_first_object); } else { $position_verb = try_to_decide_verb($sentence_2); deby("
decided position verb = $position_verb"); if ($position_verb == INVALID_POSITION) { for ($c=0; $c < sizeof($sentence); $c++) if (isset($sentence_2[$c]['passive_participle'])) $sentence[$c]['passive_participle'] = true; output_make_selection(); output(print_sentence_alternatives_verb($sentence)); throw new sentence_exception('decision verb',$position,$position_first_object); } else { $sentence[$position_verb]['verb'] = true; //$sentence[$position_verb]['decision'] = 'machine'; } } } } //deby( "
corrected position verb = $position_verb"); list($error,$position_first_object,$anchor_verb,$gerund) = analyse_verb_clause($sentence,$position_verb,$question_verb,false,$l_value,L_TYPE); // if ($error) return array($error,$position_first_object); if ($error) { if (!$phrase_mode) throw new sentence_exception('missing verb',$position,$position_first_object); } else { if ($relative) $sentence[$anchor_verb]['relative'] = true; $sentence[$anchor_verb]['level'] = $level; //$sentence[$anchor_verb]['l_value'] = $l_value; //$sentence[$anchor_verb]['l_type'] = L_TYPE; } deby( "
position first obj = $position_first_object, subject = $position_subject"); // print_r($sentence); //echo $position_verb . " " . $position_first_object; // $all_clauses[] = array_slice($sentence,$position_verb,$position_first_object-$position_verb); //$sentence[$position_first_object]['m_value'] = $position_verb; //$sentence[$position_first_adverbial_clause]['m_value'] = $position_verb; $pos = $position; while (1) { list($error,$pos) = analyse_adverbial_clause($sentence,$pos,$level,true,$skim_mode,false, $anchor_verb,$pos,$anchor_verb,false); if ($error == 'empty') break; } $pos = $position_subject; if (!$error_subject) { list($error,$pos,$anchor_subject) = analyse_there($sentence,$position_subject); if ($error) { deby("
Analysiere subjekt an $position_subject"); list($error,$pos,$anchor_subject) = analyse_object_clause($sentence,$position_subject,$level,false,$skim_mode,false, L_VALUE_END,$position_subject,L_TYPE_END,L_VALUE_END,true,false,true); if ($error) // return array($error,$pos); throw new sentence_exception('missing subject',$position,$pos); } $new_subject_loaded = true; //$sentence[$anchor_subject]['subject'] = true; } deby( "
anchor subject = $anchor_subject"); if ($anchor_verb == INVALID_POSITION) { deby("
### verlasse analyse assertion frühzeitig weil kein verb da ist ###"); return array(false,$position_verb,$anchor_verb,$gerund,$anchor_subject); } //if (!$gerund_mode) if ($anchor_subject != INVALID_POSITION) { if (!isset($new_subject_loaded)) $anchor_subject = add_reference_word_to_sentence($sentence,$anchor_subject); /* $sentence[$anchor_verb]['l_value'] = $anchor_subject; $sentence[$anchor_verb]['l_type'] = L_TYPE; */ $sentence[$anchor_subject]['l_value'] = $anchor_verb; $sentence[$anchor_subject]['l_type'] = S_TYPE; } // else // { // set_l_value_end($sentence[$anchor_verb]); //$sentence[$anchor_verb]['gerund'] = true; // } if ($gerund) $sentence[$anchor_verb]['gerund'] = true; $number_of_objects = 2; $error_first_object = 'empty'; $error_second_object = 'empty'; if ($expect_noun) //if (isset($sentence[$anchor_verb]['number_of_objects']) && !isset($sentence[$anchor_verb]['no_machine_decision_objects'])) // $number_of_objects = $sentence[$anchor_verb]['number_of_objects']; //else { $sentence_2 = $sentence; $position_new_object[0] = $position_first_object; for ($c=0; $c < 3; $c++) { list($error_new_object,$position_new_object[$c+1],$anchor_new_object[$c]) = analyse_object_clause_and_verb_adjectives($sentence_2,$position_new_object[$c],$level,true,/*$skim_mode*/ true,true, $anchor_verb,$position_new_object[$c],M_TYPE,$anchor_verb,true,true,false); if ($error_new_object=='empty') break; } if ($c==0) $number_of_objects = 0; else if ($anchor_verb_of_expecting_noun == INVALID_POSITION) $number_of_objects = $c-1; else if (isset($sentence[$anchor_verb_of_expecting_noun]['passive'])) $number_of_objects = $c; else if (isset($sentence[$anchor_verb]['passive'])) { if ($c >= 2) $number_of_objects = $c-1; } else if ($c >= 3) $number_of_objects = $c-1; else { $sentence[$anchor_verb]['anchor_verb_of_expecting_noun'] = $anchor_verb_of_expecting_noun; $sentence[$anchor_verb]['whole_number_of_objects'] = $c; if (isset($sentence[$anchor_verb]['number_of_objects']) && !isset($sentence[$anchor_verb]['no_machine_decision_objects'])) $number_of_objects = $sentence[$anchor_verb]['number_of_objects']; else { //if (isset(end)) $number_of_objects = try_to_determine_number_of_objects($sentence,$anchor_verb_of_expecting_noun,$anchor_verb,$anchor_new_object[$c-1],$c); deby ("
Hier decision of objects " . isset($sentence[$anchor_verb]['no_machine_decision_objects'])); if ($number_of_objects < 0 || isset($sentence[$anchor_verb]['no_machine_decision_objects'])) { unset($sentence[$anchor_verb]['no_machine_decision_objects']); output_make_selection(); output(print_sentence_alternatives_number_of_objects($sentence,$anchor_verb_of_expecting_noun,$anchor_verb,$anchor_new_object[$c-1],$c)); throw new sentence_exception('decision number of objects',$position,$anchor_verb); } else { /* if ($number_of_objects != $c) $sentence[$anchor_verb]['decision_number_of_objects'] = array('verb' => $anchor_verb, 'number_of_objects' => $number_of_objects); else $sentence[$anchor_verb]['decision_number_of_objects'] = array('verb' => $anchor_verb_of_expecting_noun, 'number_of_objects' => 2); */ $sentence[$anchor_verb]['number_of_objects'] = $number_of_objects; /*$sentence[$anchor_verb]['whole_number_of_objects'] = $c; $sentence[$anchor_verb]['anchor_verb_of_expecting_noun'] = $anchor_verb_of_expecting_noun; */ } } /* if (isset($sentence[$anchor_verb_of_expecting_noun]['passive'])) $number_of_objects = $c; else if (isset($sentence[$anchor_verb]['passive'])) if ($c >= 2) $number_of_objects = $c-1; */ } } //try_to_locate_end_of_assertion($sentence,$anchor_verb_of_expecting_noun,N_TYPE,$anchor_verb,M_TYPE); /* if ($error_) list($error_second_object,$position_new_object,$anchor_second_object) = analyse_object_clause($sentence_2,$position_second_object,$expect_noun,true,true,$anchor_verb,N_TYPE,$anchor_verb); list($error_new_object,$position_last_adverbial_clause,$anchor_new_object) = analyse_object_clause($sentence_2,$position_new_object,$expect_noun,true,true,$anchor_verb,M_TYPE,$anchor_verb); if ($error_second_object) { if ($anchor_verb_of_expecting_noun == INVALID_POSITION) $number_of_objects = 0; else try_to_locate_end_of_assertion($sentence,$anchor_verb_of_expecting_noun,N_TYPE,$anchor_verb,M_TYPE); } else { }*/ if ($number_of_objects >= 1) { list($error_first_object,$position_second_object,$anchor_first_object) = analyse_object_clause_and_verb_adjectives($sentence,$position_first_object,$level,true,$skim_mode,true, $anchor_verb,$position_first_object,M_TYPE,$anchor_verb,true,true,false); deby( "
position second object = $position_second_object"); $position_last_adverbial_clause = $position_second_object; } else $position_last_adverbial_clause = $position_first_object; // if ($error && $error != 'empty') // return array($error,$position_second_object); if ($number_of_objects >= 2) { list($error_second_object,$position_last_adverbial_clause,$anchor_second_object) = analyse_object_clause_and_verb_adjectives($sentence,$position_second_object,$level,$expect_noun,$skim_mode,true, $anchor_verb,$position_second_object,N_TYPE,$anchor_verb); // $all_clauses[] = array_slice($sentence,$position_first_object,$position_last_adverbial_clause-$position_first_object); deby( "
position last adverbial clause = $position_last_adverbial_clause"); } // else // $position_last_adverbial_clause = $position_second_object; if ($extern_anchor_subject != INVALID_POSITION && isset($new_subject_loaded) && $level > 0) //$extern_anchor_subject != $anchor_subject) { if ($error_second_object != 'empty') throw new sentence_exception("too many objects in relative clause",$position,$position_second_object); else { $referred_extern_anchor_subject = add_reference_word_to_sentence($sentence,$extern_anchor_subject); deby( "
SO, anchor_subject = $anchor_subject, extern_anchor_subject = $extern_anchor_subject"); $sentence[$referred_extern_anchor_subject]['l_value'] = $anchor_verb; $sentence[$referred_extern_anchor_subject]['l_type'] = N_TYPE; /* if ($error_first_object == 'empty') $sentence[$extern_anchor_subject]['l_type'] = M_TYPE; else $sentence[$extern_anchor_subject]['l_type'] = N_TYPE; */ } } else if ($error_second_object == 'empty') if (!$error_first_object) $sentence[$anchor_first_object]['l_type'] = N_TYPE; // if ($position_second_object != $position_last_adverbial_clause) // if ($position_first_object != $position_second_object_clause) // if ($anchor_second_object == INVALID_POSITION) // if ($anchor_first_object != INVALID_POSITION) // if ($error && $error != 'empty') // return array($error,$position_last_adverbial_clause); // echo "last adverb = " . $position_last_adverbial_clause; //list($error,$position_sentence_end) = skim_adverbial_clause($sentence,$position_last_adverbial_clause,"max"); // $all_clauses[] = array_slice($sentence,$position_last_adverbial_clause,sizeof($sentence)-$position_last_adverbial_clause); //$sentence[$position_last_adverbial_clause]['m_value'*] = $position_verb; /* foreach (array($position,$position_last_adverbial_clause) as $pos) { if ($pos==$position) $expect_noun = true; else $expect_noun = false; while (1) { list($error,$pos) = analyse_adverbial_clause($sentence,$pos,$expect_noun,$skim_mode,$anchor_verb); if ($error == 'empty') break; //if ($error) return array($error,$pos); } } */ $pos = $position_last_adverbial_clause; while (1) { list($error,$pos) = analyse_adverbial_clause($sentence,$pos,$level,$expect_noun,$skim_mode,true, $anchor_verb,$pos,$anchor_verb,true); if ($error == 'empty') break; } deby("
position nach ende des satzes: $pos"); //print_r($sentence); // list($error,$pos) = analyse_adverbial_clause($sentence,$position_last_adverbial_clause,$position_verb); // if ($error && $error != 'empty') return array($error); //deby_die($sentence); if (isset($sentence[$anchor_verb]['passive']) && $change_passive_to_active) // && !$skim_mode) { //deby( "

$position_second_object != $position_last_adverbial_clause

"); //if ($position_second_object != $position_last_adverbial_clause) if (!$error_second_object) throw new sentence_exception("unexpected second object given passive verb",$position,$position_second_object); $object = get_child($sentence,$anchor_verb,N_TYPE); //if (!$gerund_mode) if ($anchor_subject != INVALID_POSITION) { $sentence[$anchor_subject]['l_value'] = $anchor_verb; $sentence[$anchor_subject]['l_type'] = M_TYPE; } /* if ($object != INVALID_POSITION) { //$sentence[$object]['l_type'] = N_TYPE; // if (!$gerund_mode) // $sentence[$anchor_subject]['l_type'] = M_TYPE; } else */ if ($object == INVALID_POSITION) { //throw new sentence_exception("2 obj",$position,$position_second_object); // if (!$gerund_mode) if ($anchor_subject != INVALID_POSITION) $sentence[$anchor_subject]['l_type'] = N_TYPE; remove_to_from_dative_object($sentence,$anchor_verb); } $by_preposition = get_child($sentence,$anchor_verb,L_TYPE,WORD_BY); deby( "
by_preposition = $by_preposition"); // echo print_sentence_detailed($sentence); die(); if ($by_preposition != INVALID_POSITION) { $by_subject = get_child($sentence,$by_preposition,M_TYPE); set_l_value_drop($sentence[$by_preposition]); //,false); //set_l_value_end($sentence[$by_subject]); //add_reference_word_to_sentence($sentence,$anchor_verb,$by_subject,L_TYPE); $sentence[$by_subject]['l_value'] = $anchor_verb; $sentence[$by_subject]['l_type'] = S_TYPE; //echo "anchor_verb = $anchor_verb"; echo print_sentence_detailed($sentence); die(); $anchor_subject = $by_subject; } else { deby( "
leider kann ich das subject nicht mit dem verb verknüpfen"); //set_l_value_unknown($sentence[$anchor_verb]); // set_l_value_end($sentence[$anchor_verb]); } //deby(print_sentence_detailed($sentence)); die(); unset($sentence[$anchor_verb]['passive']); } else remove_to_from_dative_object($sentence,$anchor_verb); //deby_die($sentence); deby( "
-------- verlasse analyse_assertion -----------"); return array(false,$pos,$anchor_verb,$gerund,$anchor_subject); //return array($error); //,$all_clauses); } function remove_to_from_dative_object(&$sentence,$anchor_verb) { $to_preposition = get_child($sentence,$anchor_verb,L_TYPE,WORD_TO); if ($to_preposition != INVALID_POSITION) { $to_object = get_child($sentence,$to_preposition,M_TYPE); set_l_value_drop($sentence[$to_preposition]); save_l_value($sentence[$to_object]); $sentence[$to_object]['l_value'] = $anchor_verb; //$sentence[$to_object]['l_type'] = M_TYPE; } } function print_sentence($sentence) { $text = ""; foreach ($sentence as $item) { $text .= get_name_of_word_in_sentence($item) . " "; } return $text; } function print_sentence_list($sentence_list) { $text = ""; foreach ($sentence_list as $sentence) { //echo "
ÖÖÖ"; //var_dump($sentence['sentence']); $text .= print_sentence($sentence) . "
"; } return $text; } function print_sentence_detailed($sentence) { $text = ""; $pos = 0; $text .= ""; //border=\"1\" >"; $labels = array(array('word','name'),array('word','type'),array('word','selected'),'pos','l_value','l_type','relative', 'passive','modal_verb','reference','gerund','passive_participle','verb','decision', /*'anchor_verb'*/ 'former_l_value','number_of_objects','level' /*,'pre_decided_l_value'*/, 'article_the','article_a' /*,'subject'*/, 'continuous','have','had','will','would','did','preposition', 'reference_for_cluster_id' ); //'m_value','n_value'); foreach ($labels as $label) { $text .= ""; if (sizeof($label)>1) { $text .= ""; $sub_label = $label[1]; $label = $label[0]; } else { $text .= ""; $sub_label = ""; } foreach ($sentence as $item) { $text .= ""; } $text .= ""; } $text .= "
" . $label[1] . "" . $label . ""; if ($label == 'pos') $text .= $pos++; /* if (sizeof($label)>1) { //$item = $item[$label[0]]; } */ else if (isset($item[$label])) { if (sizeof($item[$label]) > 1) { $text .= ""; foreach ($item[$label] as $sub_item) if ($sub_label=="") $text .= ""; else if (isset($sub_item[$sub_label])) $text .= ""; else $text .= ""; $text .= "
" . $sub_item . "
" . $sub_item[$sub_label] . "
" . "-" . "
"; } else if ($sub_label=="") $text .= $item[$label]; else if (isset($item[$label][0][$sub_label])) $text .= $item[$label][0][$sub_label]; } $text .= "
"; return $text; } $decision_depth; $decision_sequence; //} /* function skim_adverbial_clause(&$sentence,$position,$level,$expect_noun=false,$size="max",$expect_assertion=false) { $sentence_2 = $sentence; return analyse_adverbial_clause($sentence_2,$position,$level,$expect_noun,true,false,INVALID_POSITION,$expect_assertion); }*/ function get_parent_word_allowing_prepositional_children(&$sentence,$position) { while (1) { while (1) { if (is_verb_selected($sentence,$position) && isset($sentence[$position]['relative'])) //$position = get_child($sentence,$position,S_TYPE); $position = get_referring_child($sentence,$position); else { if (isset($sentence[$position]['reference'])) { $position = $sentence[$position]['reference']; break; } else if (!isset($sentence[$position]['l_value'])) { deby(print_sentence_detailed($sentence)); return INVALID_POSITION; } else $position = $sentence[$position]['l_value']; } if ($position == INVALID_POSITION) { //deby( " sehr merkwürdig.... mit skip=" . $skip); break; } if (is_and($sentence[$position]['word'])) $skip = true; if (is_verb_selected($sentence,$position)) // && !isset($sentence[$position]['gerund'])) //($word['type'] & $WORD_TYPE_BIT['verb']) //&& !isset($sentence[$position]['gerund'])) break; if (is_noun_or_gerund_selected($sentence,$position)) break; } if (isset($skip)) unset($skip); else break; } return $position; } function _old_get_parent_word_allowing_prepositional_children(&$sentence,$position) { global $WORD_TYPE_BIT; //echo print_sentence_detailed($sentence); die(); while (1) //$position != INVALID_POSITION) { //$previous_position = $position; $previous_position = $position; //echo $previous_word = get_selected_word($sentence[$position]['word']); // echo "pos = $position"; // echo print_sentence_detailed($sentence); die(); // if (isset($sentence[$position]['l_value'])) if (isset($sentence[$position]['reference'])) { $position = $sentence[$position]['reference']; break; } else if (!isset($sentence[$position]['l_value'])) { deby(print_sentence_detailed($sentence)); return INVALID_POSITION; } else $position = $sentence[$position]['l_value']; /* else { $position = INVALID_POSITION; break; } */ if ($position == INVALID_POSITION) { deby( " sehr merkwürdig...."); //echo print_sentence_detailed($sentence); // $position = $previous_position; break; } //$word = get_selected_word($sentence[$position]['word']); //echo "
Grummel: neue preposition-pos = $position | " . $word['type']; // if ($word['type'] & ($WORD_TYPE_BIT['verb'] | $WORD_TYPE_BIT['noun']) ) if (is_verb_selected($sentence,$position) && !isset($sentence[$position]['gerund'])) //($word['type'] & $WORD_TYPE_BIT['verb']) //&& !isset($sentence[$position]['gerund'])) break; //if ($word['type'] & $WORD_TYPE_BIT['noun']) if (is_noun_or_gerund_selected($sentence,$position)) { // //if ($previous_word['type'] & $WORD_TYPE_BIT['verb']) if (is_verb_selected($sentence,$previous_position) && !isset($sentence[$previous_position]['gerund'])) { if (isset($sentence[$previous_position]['relative'])) { $position = get_reference_child($sentence,$previous_position); } else { $position = INVALID_POSITION; //break; } } //else break; } } return $position; } /* function check_for_end_of_object($sentence,$position_start,$predicate_of_object,$position) //,$allow_refering_outside_of_sentence) { $l_value = $sentence[$position]['l_value']; // if ($l_value < $position_start) // $sentence[$position]['end_of_sentence_marker'] = true; if ($l_value==$predicate_of_object || $l_value < $position_start) return true; else return false; } */ function analyse_adverbial_clause(&$sentence,$position,$level,$expect_noun=false,$skim_mode,$allow_refering_outside_of_sentence=false, $predicate_of_object=L_VALUE_END,$start_position_object,$l_value, $expect_assertion=false) { /* //global $WORD_TYPE; $position_start = $position; $error = false; if (isset($sentence[$position]) && is_preposition($sentence[$position]['word'],true)) //$sentence[$position]['type'] == $WORD_TYPE['preposition']) { $sentence[$position]['l_type'] = L_TYPE; $sentence[$position++]['l_value'] = $l_value; list($error,$position,$anchor) = analyse_object_clause($sentence,$position,$expect_noun,false,$allow_refering_outside_of_sentence,$l_value,M_TYPE,$position-1); } else $error = 'empty'; */ $position_start = $position; //deby( ", predikat = $predicate_of_object, skim_mode = $skim_mode"); $error = false; //$l_value = $predicate_of_object; while (1) { if (isset_primary_sentence_position($sentence,$position) && (is_preposition($sentence[$position]['word'],true))) // || $and = is_and($sentence[$position]['word'],true)) ) //$sentence[$position]['type'] == $WORD_TYPE['preposition']) { //deby(print_sentence_detailed($sentence)); die(); $sentence[$position]['l_type'] = L_TYPE; //if (!$skim_mode) { /*if (isset($sentence[$position]['l_value'])) { if ($sentence[$position]['l_value'] == $predicate_of_object || $sentence[$position]['l_value'] < $position_start) //if (check_for_end_of_object($sentence,$position_start,$predicate_of_object,$position)) break; } else */ load_l_value_with_decision($sentence,$position); load_l_value_options($sentence,$position,$l_value,$predicate_of_object,$allow_refering_outside_of_sentence); if (sizeof($sentence[$position]['l_value']) > 1) { //try_to_decide_l_value($sentence,$position); //$sentence[$position]['decision'] = "user"; //$decision_position = $position; deby( "
hier nun eine decision!"); // . $error = 'decision'; //break; //$sentence_2 = $sentence; list ($error_noun,$local_anchor_noun,$new_position,$gerund) = skim_noun($sentence,$position+1,$level,$expect_noun); //analyse_noun($sentence_2,$position+1,false,true); if ($error_noun) throw new sentence_exception("missing noun after preposition",$position_start,$position); else link_forward_skimmed_noun($sentence,$position,$local_anchor_noun,$gerund); /* if ($gerund) is_verb_continuous($sentence[$local_anchor_noun]['word'],true); else is_noun($sentence[$local_anchor_noun]['word'],true); //$sentence[$local_anchor_noun]['word'] = $sentence_2[$local_anchor_noun]['word']; deby( "
Local Anchor noun for preposition = $local_anchor_noun"); if (!$error_noun) { $sentence[$local_anchor_noun]['l_value'] = $position; //deby( "
Setze Objekt $position auf l_value=$l_value, wobei new_pos = $new_position"); $sentence[$local_anchor_noun]['l_type'] = M_TYPE; } else */ /* if ($and) { deby("
nein kein noun after and"); unset($sentence[$position]['l_value']); $error = false; break; } else */ //throw new sentence_exception("missing noun after preposition",$position_start,$position); //$sentence[$position]['decision']['anti_l_value'] = $local_anchor_noun; //echo print_sentence_detailed($sentence); die(); deby( "
nun entscheidung "); if (!isset($sentence[$position]['no_machine_decision']) && /*(!$and &&*/ (($decided_position = try_to_decide_l_value($sentence,$local_anchor_noun)) != INVALID_POSITION)) { //deby("
Setze computer decision an position=$position mit der decided pos= $decided_position"); select_decided_l_value($sentence,$position,$decided_position); //deby(print_sentence_detailed($sentence)); } else //if (sizeof($sentence[$position]['l_value']) > 1) { if ($skim_mode) { if (is_likely_prepositon_associated_with_predicate($sentence[$position]['raw_word']) && $predicate_of_object != INVALID_POSITION) $sentence[$position]['l_value'] = $predicate_of_object; else $sentence[$position]['l_value'] = $sentence[$position]['l_value'][0]; //$sentence[$position]['l_type'] = L_TYPE; } else { unset($sentence[$position]['no_machine_decision']); output_make_selection(); output(print_sentence_alternatives($sentence)); throw new sentence_exception('decision',$position_start,$position); } } /* { $error = 'decision'; break; }*/ } /* else { //set_l_value($sentence,$position,$sentence[$position]['l_value'][0]); $sentence[$position]['l_value'] = $sentence[$position]['l_value'][0]; $sentence[$position]['l_type'] = L_TYPE; //if ($sentence[$position]['l_value'] == $predicate_of_object) //if (check_for_end_of_object($sentence,$position_start,$predicate_of_object,$position)) // break; } } */ else deby( "
HEY, V-POS gesetzt bei $position"); if (sizeof($sentence[$position]['l_value']) == 1) { //deby("
start with noun = $start_with_noun, L_value = " . $sentence[$position]['l_value']); //if (isset($sentence[$position]['anchor_verb'])) // deby(" anchor verb = " . $sentence[$position]['anchor_verb']); if ($sentence[$position]['l_value'] == $predicate_of_object) //|| (isset($sentence[$position]['anchor_verb']) && $sentence[$position]['l_value'] == $sentence[$position]['anchor_verb'])) { deby("
hello es geht"); if ($position_start != $start_position_object) //($start_with_noun /*|| $and*/) break; } else { if ($sentence[$position]['l_value'] < $start_position_object)// || $sentence[$position]['l_value'] > $position) break; if ($sentence[$position]['l_value'] > $position) if ($predicate_of_object != INVALID_POSITION || $position_start != $start_position_object) //$start_with_noun || $and) break; } } } //if (!isset($sentence[$position]['anchor_verb'])) // $sentence[$position]['anchor_verb'] = $predicate_of_object; $l_value = $position; $position++; list($error,$position,$anchor) = analyse_object_clause($sentence,$position,$level,$expect_noun,$skim_mode,$allow_refering_outside_of_sentence, /*$l_value*/ $predicate_of_object,$start_position_object, M_TYPE,$l_value,false,$expect_assertion,false); if ($error) throw new sentence_exception("missing noun after preposition",$position_start,$position); } //else // break; break; } if (/*!$error &&*/ $position_start==$position) $error = 'empty'; return array($error,$position); } function analyse_object_clause_and_verb_adjectives(&$sentence,$position,$level,$expect_noun=false,$skim_mode=false,$allow_refering_outside_of_sentence=false, $predicate_of_object = L_VALUE_END /* this is the predicate left to the object */, $start_position_object, $l_type = M_TYPE /* could be m_ or n_value depending on whether the object is a first or second one */, $l_value = L_VALUE_END /* this is a possible preposition left to the object */, $start_with_noun=true,$expect_assertion=false,$subject=false) { list($error,$position,$anchor_of_object) = analyse_object_clause($sentence,$position,$level,$expect_noun,$skim_mode, $allow_refering_outside_of_sentence, $predicate_of_object,$start_position_object,$l_type,$l_value,$start_with_noun,$expect_assertion,$subject); if ($error == 'empty') { list($error_adjective,$position) = analyse_adjectives_for_verb($sentence,$position,$level,$predicate_of_object); if (!$error_adjective) list($error,$position,$anchor_of_object) = analyse_object_clause($sentence,$position,$level,$expect_noun,$skim_mode, $allow_refering_outside_of_sentence, $predicate_of_object,$start_position_object,$l_type,$l_value,$start_with_noun,$expect_assertion,$subject); } return array($error,$position,$anchor_of_object); } function analyse_object_clause(&$sentence,$position,$level,$expect_noun=false,$skim_mode=false,$allow_refering_outside_of_sentence=false, $predicate_of_object = L_VALUE_END /* this is the predicate left to the object */, $start_position_object, $l_type = M_TYPE /* could be m_ or n_value depending on whether the object is a first or second one */, $l_value = L_VALUE_END /* this is a possible preposition left to the object */, $start_with_noun=true,$expect_assertion=false,$subject=false) { $start_position = $position; /* list($error,$position,$anchor_of_object) = analyse_variable($sentence,$position,$l_value,$l_type); if (!$error) is_noun($sentence[$anchor_of_object]['word'],true); else */ while (1) { list($error,$position,$anchor_of_object) = analyse_one_object_clause($sentence,$position,$level,$expect_noun,$skim_mode,$allow_refering_outside_of_sentence, $predicate_of_object,$start_position_object,$l_type,$l_value, $start_with_noun,$expect_assertion,$subject); if ($error) break; //deby("
nach analyse one assertion: " . print_sentence_detailed($sentence)); $l_value = $position; //$l_type = L_TYPE; list($error_and,$position) = analyse_and($sentence,$position,$anchor_of_object,$skim_mode); if ($error_and) break; if ($start_position == $start_position_object) $start_position_object = $position; list($error,$position,$second_anchor_of_object) = analyse_object_clause($sentence,$position,$level,$expect_noun,$skim_mode,$allow_refering_outside_of_sentence, $predicate_of_object,$start_position_object,L_TYPE /*$l_type*/,$l_value, $start_with_noun,$expect_assertion,$subject); break; } return array($error,$position,$anchor_of_object); } function _old_analyse_object_clause(&$sentence,$position,$level,$expect_noun=false,$skim_mode=false,$allow_refering_outside_of_sentence=false, $predicate_of_object = L_VALUE_END /* this is the predicate left to the object */, $start_position_object, $l_type = M_TYPE /* could be m_ or n_value depending on whether the object is a first or second one */, $l_value = L_VALUE_END /* this is a possible preposition left to the object */, $start_with_noun=true,$expect_assertion=false,$subject=false) { // $right_value = INVALID_POSITION; // $last_and = INVALID_POSITION; $first_anchor_of_object = INVALID_POSITION; while (1) { list($error,$position,$anchor_of_object) = analyse_one_object_clause($sentence,$position,$level,$expect_noun,$skim_mode,$allow_refering_outside_of_sentence, $predicate_of_object,$start_position_object,$l_type,$l_value, $start_with_noun=true,$expect_assertion,$subject); list($error_and,$position,$l_value,$first_anchor_of_object) = analyse_and_plus_header($sentence,$position,$error,$first_anchor_of_object,$anchor_of_object,$skim_mode); deby("- erhalte: list($error,$position,$l_value,$first_anchor_of_object)"); if ($error_and) break; /* if ($first_anchor_of_object == INVALID_POSITION) $first_anchor_of_object = $anchor_of_object; if ($error) break; $l_value = $position; deby("bin bei object analyse und gehe jetzt auf and zu mit anchor_of_object = $anchor_of_object"); list($error_and,$position) = analyse_and($sentence,$position,$anchor_of_object,$skim_mode); // list($error_and,$position,$right_value,$last_and) = // analyse_and_link_and($sentence,$position,$skim_mode,$anchor_of_object,$right_value,$last_and,$anchor_of_object); if ($error_and) break; */ } return array($error,$position,$first_anchor_of_object); } function analyse_one_object_clause(&$sentence,$position,$level,$expect_noun=false,$skim_mode=false,$allow_refering_outside_of_sentence=false, $predicate_of_object = L_VALUE_END /* this is the predicate left to the object */, $start_position_object, $l_type = M_TYPE /* could be m_ or n_value depending on whether the object is a first or second one */, $l_value = L_VALUE_END /* this is a possible preposition left to the object */, $start_with_noun=true,$expect_assertion=false,$subject=false) { //global $WORD_TYPE; deby( "
Analyse Object: start position = $position"); $position_start = $position; deby( ", predikat = $predicate_of_object, skim_mode = $skim_mode"); $error = false; //$object_mode = $start_with_noun; //$verb_value = $m_value; //if ($l_value == L_VALUE_END) // $l_value = $predicate_of_object; $anchor_of_object = INVALID_POSITION; //$last_passive_participle = INVALID_POSITION; while (1) { if (!isset_primary_sentence_position($sentence,$position)) break; //{ //if ($start_with_noun) //if (!$adverbial_mode) { //$type = $sentence[$position]['type']; //if (is_noun($sentence[$position]['word'],true)) //$type == $WORD_TYPE['noun'] || $type == $WORD_TYPE['noun_plural'] || $type == $WORD_TYPE['noun_proper']) deby( "
analyse noun an position $position: expect noun = $expect_noun, l_value= $l_value"); list ($error_noun,$position,$new_position,$gerund) = analyse_noun($sentence,$position,$level,$expect_noun,$skim_mode,$l_value,$l_type,$expect_assertion); //deby(print_sentence_detailed($sentence)); die(); if (!$error_noun) { //$sentence[$position]['l_value'] = $l_value; //deby( "
Setze Objekt $position auf l_value=$l_value, wobei new_pos = $new_position"); //$sentence[$position]['l_type'] = $l_type; $l_value /*$last_l_value*/ = $position; //$noun_value = $position; $l_type = M_TYPE; // if ($anchor_of_object == INVALID_POSITION) $anchor_of_object = $position; if ($subject) $sentence[$anchor_of_object]['subject'] = true; $position = $new_position; } else { $error = $error_noun; break; } } if (isset_primary_sentence_position($sentence,$position) && (is_verb_continuous($sentence[$position]['word']) || is_verb_perfect_tense($sentence[$position]['word'])) ) // && $anchor_of_object != INVALID_POSITION) { //if (is_be($sentence[$position]['word']) || is_have($sentence[$position]['word'])) // break; $sentence_2 = $sentence; if (is_verb_perfect_tense($sentence_2[$position]['word'])) { if (isset($sentence_2[$position]['verb'])) break; $sentence_2[$position]['passive'] = true; //$last_passive_participle = $position; //set_last_passive_participle($position); $sentence_2[$position]['passive_participle'] = true; } //$sentence[$position]['reference'] = $anchor_of_object; deby( "RELATIV-GERUND!"); //if (!$skim_mode) //$reference_word = add_reference_word_to_sentence($sentence_2,$l_value /*$anchor_of_object*/,INVALID_POSITION,L_TYPE_END); //,$l_value,L_TYPE); //else // $reference_word = 0; try { list($error,$position,$anchor_verb,$gerund,$anchor_subject) = /*skim_or_analyse_assertion*/ analyse_assertion($sentence_2,$position,$level+1,$expect_noun,$skim_mode,$l_value,true,true,INVALID_POSITION,false,$predicate_of_object,true); //= skim_or_analyse_assertion($sentence,$position,$skim_mode,$reference_word,false,true,INVALID_POSITION,true); } catch (sentence_exception $exception) { if ($exception->error=='unexpected second object given passive verb') { break; } else { $sentence = $sentence_2; throw $exception; } } $sentence = $sentence_2; //deby(print_sentence_detailed($sentence)); die(); if ($error) throw new sentence_exception("partizip without following relative clause",$position_start,$position); //$sentence[$anchor_verb]['relative'] = true; unset($sentence[$anchor_verb]['gerund']); } if (isset_primary_sentence_position($sentence,$position) && is_relative_pronoun($sentence[$position]['word'],true)) { //$sentence[$position]['reference'] = $l_value; //$anchor_of_object; //$sentence[$position]['l_value'] = $l_value /*$last_l_value*/; //$anchor_of_object; //$sentence[$position]['l_type'] = L_TYPE; set_l_value_drop($sentence[$position]); list($error,$position,$anchor_verb,$gerund,$anchor_subject) = /*skim_or_analyse_assertion*/ analyse_assertion($sentence,$position+1,$level+1,$expect_noun,$skim_mode,$l_value,false,true,INVALID_POSITION,true,$predicate_of_object,true); deby( "
nach der analyse des nebensatzes gibts error $error : skim-mode $skim_mode; position ist = $position"); if ($error) throw new sentence_exception("who or which without following relative clause",$position_start,$position); //$sentence[$anchor_verb]['relative'] = true; //mark_l_value_relative($sentence,$anchor_verb); // return array($error,$position,$anchor_of_object); } //$and = false; list($error_adverbial,$position) = analyse_adverbial_clause($sentence,$position,$level,$expect_noun,$skim_mode ,$allow_refering_outside_of_sentence, $predicate_of_object,$start_position_object,$l_value,$expect_assertion); deby("
nach der adverbial clause aufruf: " . print_sentence_detailed($sentence)); //$start_with_noun = true; /*} else break;*/ break; } // if ($error == 'decision') // throw new sentence_exception("decision",$position_start,$position); if (/*!$error &&*/ $position_start==$position) $error = 'empty'; deby( "
Verlasse objekt-analyse mit error=$error an position = $position"); return array($error,$position,$anchor_of_object); } function skim_noun(&$sentence,$position,$level,$expect_noun=false) { $sentence_2 = $sentence; //list($error,$position_noun,$position) = return analyse_noun($sentence_2,$position,$level,$expect_noun,true); //return array($error,$position); } /* function skim_noun(&$sentence,$position) { $position_start = $position; $error = false; $position_last_verb_continuous = INVALID_POSITION; $noun_occured = false; while (isset($sentence[$position])) { echo "
skim noun pos = " . $position; $current_word = $sentence[$position]['word']; if (!$noun_occured) { if ( ! (is_noun($current_word) || is_adjective($current_word) || is_adverb($current_word) || is_verb_continuous($current_word)) ) // || is_verb_continuous($current_word))) { if ($position_last_verb_continuous != INVALID_POSITION) $position = $position_last_verb_continuous+1; else $error = true; break; } if (is_noun($current_word)) $noun_occured = true; if (is_verb_continuous($current_word)) $position_last_verb_continuous = $position; } else if (!(is_noun($current_word))) break; $position++; } test_error_empty($error,$position_start,$position); return array($error,$position); } */ /*function destroy_empty_error(&$error) { if ($error == 'empty') $error = false; }*/ function test_error_empty(&$error,$position_start,$position) { if (!$error && $position_start == $position) $error = 'empty'; } function skim_adjective(&$sentence,$position,$level,$position_last_verb_continuous) { $position_start = $position; $error = false; list($error_adverb,$position) = skim_adverb($sentence,$position); //destroy_empty_error($error); // if (!$error_adverb || $error_adverb=='empty') if (isset_primary_sentence_position($sentence,$position)) { if (is_adjective($sentence[$position]['word']) || is_verb_perfect_tense($sentence[$position]['word']) ) { $position++; // $error = false; } else if (is_verb_continuous($sentence[$position]['word'])) { $position_last_verb_continuous = $position; $position++; } else $position = $position_start; } else $position = $position_start; test_error_empty($error,$position_start,$position); return array($error,$position); } /* function skim_adjective(&$sentence,$position) { $start_position = $position; $error = false; while (1) if (is_adverb($sentence[$position]['word'])) $position++; else { if (is_adjective($sentence[$position]['word'])) $position++; else if ($start_position != $position) $error = true; break; } // test_error_empty($error,$start_position,$position); return array($error,$position); } */ function skim_adverb(&$sentence,$position) { // return array('empty',$position); $position_start = $position; $error = false; while (isset_primary_sentence_position($sentence,$position)) if (is_adverb($sentence[$position]['word'])) $position++; else break; test_error_empty($error,$position_start,$position); return array($error,$position); } function analyse_adverb(&$sentence,$position,$position_adjective) { $position_start = $position; $error = false; //return array('empty',$position); $precursory_adverb = false; while (isset_primary_sentence_position($sentence,$position)) { if (is_adverb($sentence[$position]['word'],true)) { set_precursory_adverb($sentence,$precursory_adverb,$position); $precursory_adverb = true; $position++; } else break; } set_precursory_adverb($sentence,$precursory_adverb,$position,$position_adjective); test_error_empty($error,$position_start,$position); return array($error,$position); } function set_relative(&$sentence,$position,$level) { $sentence[$position]['relative'] = true; $sentence[$position]['level'] = $level; } function analyse_adjectives_for_verb(&$sentence,$position,$level,$anchor) { $position_start = $position; $error = false; while (1) { list($error_adjective,$position) = analyse_adjective($sentence,$position,$level,$anchor); if ($error_adjective) break; } test_error_empty($error,$position_start,$position); return array($error,$position); } function analyse_adjective(&$sentence,$position,$level,$position_noun) { $position_start = $position; list($error,$position) = skim_adverb($sentence,$position); if (!$error || $error=='empty') { //destroy_empty_error($error); if (isset_primary_sentence_position($sentence,$position) && ( ($adjective = is_adjective($sentence[$position]['word'],true)) || ($continuous = is_verb_continuous($sentence[$position]['word'],true)) || (is_verb_perfect_tense($sentence[$position]['word'],true))) ) { $sentence[$position]['l_value'] = $position_noun; $sentence[$position]['l_type'] = L_TYPE; if (!$adjective) { //mark_l_value_relative($sentence,$position); //$sentence[$position]['relative'] = true; set_relative($sentence,$position,$level+1); if (!$continuous) { add_reference_word_to_sentence($sentence,$position_noun,$position,N_TYPE); set_l_value_end($sentence[$position]); //$sentence[$position]['passive'] = true; } } /* if ($adjective) $sentence[$position]['l_type'] = L_TYPE; else $sentence[$position]['l_type'] = W_TYPE; */ list($error,$pos) = analyse_adverb($sentence,$position_start,$position); $position++; $error = false; } else { if ($error != 'empty') throw new sentence_exception('missing adjective',$position_start,$position); } } deby( "

start=$position_start, ende=$position, noun=$position_noun

"); return array($error,$position); } function analyse_article(&$sentence,$position) { if (isset_primary_sentence_position($sentence,$position) && is_article($sentence[$position]['word'],true)) { //if ($sentence[$position]['raw_word'] == WORD_AN) return array(false,$position+1); } else return array('empty',$position); } function link_noun_sequence(&$sentence,$position_start,$position_end) //,$set_end_value_in_anchor_noun=true) { for ($c=$position_start; $c < $position_end-1; $c++) { $sentence[$c]['l_value'] = $c+1; $sentence[$c]['l_type'] = NOUN_TYPE; } // unset($sentence[$position_end-1]['l_value']); // unset($sentence[$position_end-1]['l_type']); // if ($set_end_value_in_anchor_noun) set_l_value_end($sentence[$position_end-1]); } function slice_noun_sequence(&$sentence,$position_start,$position_end) { $length = $position_end-$position_start; $partial_sentence = array_slice($sentence,$position_start,$length); link_noun_sequence($partial_sentence,0,$length); return $partial_sentence; } function get_number_occurences_of_noun_sequence(&$sentence,$position_start,$position_end) { if ($position_end-$position_start > 1) { $noun_sequence = slice_noun_sequence($sentence,$position_start,$position_end); //$result = query_sentence($noun_sequence); //($sentence,$position_start,$c); //return mysql_num_rows($result); return statistically_query_sentence($noun_sequence); } return 0; } function analyse_noun_sequence(&$sentence,$position,$expect_noun=false,$skim_mode=false) { /* list($error,$position,$anchor_noun) = analyse_variable($sentence,$position); //,$l_value,$l_type); if (!$error) is_noun($sentence[$anchor_noun]['word'],true); else {*/ $position_start = $position; $error = false; //deby ("Betrachte noun sequence mit" . isset($sentence[$position_start]['no_machine_decision_noun_sequence'])); while (isset_primary_sentence_position($sentence,$position) && is_noun($sentence[$position]['word'],true)) { if (isset($sentence[$position]['stop_marker']) && !isset($sentence[$position_start]['no_machine_decision_noun_sequence'])) { // unset($sentence[$position]['stop_marker']); $position++; $stop_marker = true; break; //return array(false,$position,$position-1); } $position++; if (isset_primary_sentence_position($sentence,$position) && (is_verb($sentence[$position]['word']) || is_variable($sentence[$position]['word'])) ) break; } if (!isset($stop_marker)) { $number_nouns = $position-$position_start; if ($expect_noun && $number_nouns > 1) { // if ($number_nouns == 2) // $position--; // else { for ($c=$position_start+1; $c <= $position; $c++) { //$first_noun_sequence = slice_noun_sequence($sentence,$position_start,$c); //$second_noun_sequence = slice_noun_sequence($sentence,$c,$position); //echo print_r($second_noun_sequence); die(); // $number_occurences = 0; $number_of_occurences[$c-$position_start-1] = get_number_occurences_of_noun_sequence($sentence,$position_start,$c) + get_number_occurences_of_noun_sequence($sentence,$c,$position); } /* $noun_sequence = slice_noun_sequence($sentence,$position_start,$c); $result = query_sentence($first_noun_sequence); //($sentence,$position_start,$c); $number_occurences = mysql_num_rows($result); $result = query_sentence($second_noun_sequence); //($sentence,$c,$position); $number_of_occurences[$c] = mysql_num_rows($result) + $number_first_occurences; */ $pos = try_to_decide_by_probability($number_of_occurences); if ($pos == INVALID_POSITION && $skim_mode) $position = 0+$position_start+1; else if ($pos == INVALID_POSITION || isset($sentence[$position_start]['no_machine_decision_noun_sequence'])) { // if ($skim_mode) // $position = 0+$position_start+1; // else { unset($sentence[$position_start]['no_machine_decision_noun_sequence']); output_make_selection(); output(print_sentence_alternatives_noun($sentence,$position_start,$position)); throw new sentence_exception('decision noun',$position_start,$position); } } else $position = $pos+$position_start+1; } } } $anchor_noun = $position-1; link_noun_sequence($sentence,$position_start,$position); //,false); test_error_empty($error,$position_start,$position); // } return array($error,$position,$anchor_noun); } function analyse_noun_no_gerund(&$sentence,$position,$level,$expect_noun=false,$skim_mode=false) { $position_start = $position; $error = false; $position_last_verb_continuous = INVALID_POSITION; $gerund = false; /* list($error_article,$position) = skim_article($sentence,$position); if (!$error_article) $article_position = $position; else $article_position = INVALID_POSITION; */ while (1) { list($error_adjective,$position) = skim_adjective($sentence,$position,$level,$position_last_verb_continuous); if ($error_adjective) break; } if (isset_primary_sentence_position($sentence,$position) && is_noun($sentence[$position]['word'] /*,true*/)) { list($error,$position,$position_noun) = analyse_noun_sequence($sentence,$position,$expect_noun,$skim_mode); $position_last_verb_continuous = $position; //if ($position >=3) //echo "
NOUN: pos=$position,nounpos=$position_noun"; //die(); //echo " -noun pos= " . $position_noun = $position; //$position++; } else /* if ($position_last_verb_continuous != INVALID_POSITION) { $gerund = true; list($error_verb,$position,$position_noun) = analyse_verb_clause($sentence,$position_last_verb_continuous); //print_r($sentence[0]); // is_verb_continuous($sentence[$position_last_verb_continuous]['word'],true); // echo " gerund= " . $position_noun = $position_last_verb_continuous; // $position = $position_noun+1; } else */ { //$error = true; //if ($position==$position_start) $error = 'empty'; //else // throw new sentence_exception('missing noun',$position_start,$position); deby( "
ich gehe jetzt mit start=$position_start und pos=$position ohne noun nach hause "); //print_r($sentence); return array($error,$position_start,$position_start); } $c = $position_start; // if (!$gerund) // $position_last_verb_continuous = $position_noun; while ($c != $position_last_verb_continuous) { deby( "** vor der adj anlyse $c ***"); list($error_adjective,$c) = analyse_adjective($sentence,$c,$level,$position_noun); deby( "** nach der adj anlyse $c *** $error_adjective **"); if ($error_adjective) break; } if ($error_adjective != 'empty') // $position = $position_noun; // else $error = $error_adjective; //$position = $position_start; // if ($error=='empty') // $error = false; // $error = false; test_error_empty($error,$position_start,$position); deby( "

sssss " . $error . "#$position_start#$position

"); return array($error,$position_noun,$position); } function skim_noun_no_gerund(&$sentence,$position,$level,$expect_noun) { $sentence_2 = $sentence; return analyse_noun_no_gerund($sentence_2,$position,$level,$expect_noun,true); } /* function _alt_analyse_noun(&$sentence,$position,$level,$expect_noun=false,$skim_mode=false,$l_value=INVALID_POSITION,$expect_assertion=false) { while (1) { list($error,$anchor_noun,$position,$gerund) = analyse_one_noun($sentence,$position,$level,$expect_noun,$skim_mode,$l_value); if ($error) break; deby("bin an position $position mit $error"); if (isset($last_and)) link_and($sentence,$last_anchor_noun,$last_and,$anchor_noun); // unset($last_and); //deby("....." . print_sentence_detailed($sentence)); list($error_and,$position_next_noun) = analyse_and($sentence,$position); //deby("....." . print_sentence_detailed($sentence)); if ($error_and) break; deby(" found and"); if ($expect_assertion) { deby("
expect assertion in $position"); try { list($error_assertion,$pos,$anchor_verb,$gerund,$anchor_subject) = skim_assertion($sentence,$position_next_noun,$level,$expect_noun,true,$anchor_subject=INVALID_POSITION); if ($error_assertion==false) break; } catch (sentence_exception $exception) { deby("
## ja es gab fehler bei der expect assertion analyse"); //break; } } $last_anchor_noun = $anchor_noun; $last_and = $position; $position = $position_next_noun; } return array($error,$anchor_noun,$position,$gerund); } */ //analyse_one_noun function analyse_noun(&$sentence,$position,$level,$expect_noun=false,$skim_mode=false,$l_value=INVALID_POSITION,$l_type=L_TYPE /*,$l_type=M_TYPE*/) { //$gerund = false; //true; $position_start = $position; list($error_article,$position) = analyse_article($sentence,$position); list($error_adverb,$pos) = skim_adverb($sentence,$position); if (isset_primary_sentence_position($sentence,$pos) && is_verb_continuous($sentence[$pos]['word'])) { try { deby("
Skime jetzt auf gerund"); list($error,$pos,$anchor_verb,$gerund,$anchor_subject) = skim_assertion($sentence,$position,$level+1,$expect_noun,INVALID_POSITION,true); deby( "
ja es funkt!"); } catch (sentence_exception $exception) { //$gerund = false; } } //if (isset($anchor_verb))// && isset($sentence[$anchor_verb]['gerund'])) // $gerund = true; //false; if (isset($gerund) && $gerund) { deby( "
ja, gerund ist gesetzt!"); if (!$error_article) { try { list($error_noun,$position_noun,$pos) = skim_noun_no_gerund($sentence,$position,$level,$expect_noun); } catch (sentence_exception $exception) { $error_noun = true; } if (!$error_noun) $gerund = false; } } else {$gerund = false; deby( "
nein, kein gerund!");} deby( "
GERUND = $gerund, wobei skim_mode=$skim_mode, position=$position, l_value=$l_value"); if ($gerund) { list($error,$position,$position_noun,$gerund,$anchor_subject) = /*skim_or_analyse_assertion*/ analyse_assertion($sentence,$position,$level+1,$expect_noun,$skim_mode,INVALID_POSITION/*$l_value*//*0*/,true,false, INVALID_POSITION,false,INVALID_POSITION,false,false,$l_value); // if ($anchor_subject != INVALID_POSITION) // add_reference_word_to_sentence($sentence,$position_noun,$anchor_subject,L_TYPE); } else list($error,$position_noun,$position) = analyse_noun_no_gerund($sentence,$position,$level,$expect_noun,$skim_mode); if (!$error) { $sentence[$position_noun]['l_value'] = $l_value; $sentence[$position_noun]['l_type'] = $l_type; } else deby("leider error noun"); if (!$error_article) { $sentence[$position_start]['l_value'] = $position_noun; $sentence[$position_start]['l_type'] = L_TYPE; } return array($error,$position_noun,$position,$gerund); } function set_precursory_adverb(&$sentence,&$precursory_adverb,$position,$anchor=INVALID_POSITION) { if ($anchor == INVALID_POSITION) $anchor = $position; if ($precursory_adverb) { $sentence[$position-1]['l_value'] = $anchor; $sentence[$position-1]['l_type'] = L_TYPE; $precursory_adverb = false; } } function analyse_realtive_clause(&$sentence,$position,$anchor_of_noun) { } function get_clause($sentence,$position) { //echo print_sentence_detailed($sentence); die(); for ($c=0; $c < sizeof($sentence); $c++) { $cur_pos = $c; while (1) { if ($cur_pos == $position) { $marker[] = $c; break; } if (isset($sentence[$cur_pos]['l_value'])) $cur_pos = $sentence[$cur_pos]['l_value']; else break; if ($cur_pos == INVALID_POSITION) break; } } return $marker; } function print_sentence_alternatives_noun($sentence,$position_start,$position_end) { $text = ""; for ($pos=$position_start+1; $pos <= $position_end; $pos++) { $pos_decremented = $pos-1; $text .= "

"; for ($c=0; $c < sizeof($sentence); $c++) { if ($position_start <= $c && $c < $pos) $text .= ''; else if ($pos <= $c && $c < $position_end) $text .= ''; else $text .= ''; $text .= get_name_of_word_in_sentence($sentence[$c]) . " "; $text .= ''; } $text .= "

"; } return $text; } function print_sentence_highlight_noun_sequence($sentence) { $text = ""; $color_pointer = 0; $color_table = array("80c0ff","40ff40"); $in_noun_sequence = false; for ($c=0; $c < sizeof($sentence); $c++) { if (!isset_primary_sentence_position($sentence,$c)) break; if ($sentence[$c]['l_type'] == NOUN_TYPE || $in_noun_sequence) { $color = $color_table[$color_pointer & 1]; if (!$in_noun_sequence) $noun_sequence_start = $c; // $color_pointer++; $in_noun_sequence = true; $text .= ""; $text .= "
"; } // else // $in_noun_sequence = false; else $text .= "
"; $text .= get_name_of_word_in_sentence($sentence[$c]) . " "; $text .= '
'; if ($in_noun_sequence) $text .= '
'; if ($sentence[$c]['l_type'] != NOUN_TYPE && $in_noun_sequence) { $in_noun_sequence = false; $color_pointer++; } /* $text .= '
'; }*/ } $text .= "
"; if ($color_pointer==0) return ""; else return $text; } function print_sentence_alternatives_number_of_objects($sentence,$anchor_verb_of_expecting_noun,$anchor_verb,$anchor_object,$number_of_objects) { // $posibilities = array($anchor_verb_of_expecting_noun,$anchor_verb) $text = "

"; $text .= print_sentence_highlighted($sentence,array($anchor_verb_of_expecting_noun,$anchor_object)); $text .= "

"; $text .= "

"; $text .= print_sentence_highlighted($sentence,array($anchor_verb,$anchor_object)); $text .= "

"; return $text; } function print_sentence_alternatives(&$sentence,$and_mode=false,$child_l_type=M_TYPE,$anchor_noun=INVALID_POSITION, $anchor_verb=INVALID_POSITION) { // deby("
Sentence alternatives: " . print_sentence_detailed($sentence)); $text = ""; for ($c=0; $c < sizeof($sentence); $c++) { if (isset($sentence[$c]['l_value']) && sizeof($sentence[$c]['l_value']) > 1) { //foreach ($sentence[$c]['l_value'] as $reference_position) //$text .= print_sentence_highlighted(array($reference_position,$c,$c+1)); for ($d=0; $d < sizeof ($sentence[$c]['l_value']); $d++) { $l_value = $sentence[$c]['l_value'][$d]; if ($and_mode) { list($highlighted_l_value,$right_value) = get_right_and_l_value_of_and_option($sentence,$l_value,$anchor_noun,$anchor_verb); /* if (is_noun_or_gerund_selected($sentence,$l_value)) { $right_value = $anchor_noun; $l_value = $sentence[$l_value]['l_value']; if ($l_value==INVALID_POSITION) $right_value = $anchor_verb; } else { $right_value = $anchor_verb; $l_value = get_referred_position($sentence,get_child($sentence,$l_value,S_TYPE)); } //$l_value = get_referred_position($sentence,$sentence[$l_value]['l_value']);*/ } else { // if ($right_value == INVALID_POSITION) $right_value = get_child($sentence,$c,$child_l_type); $highlighted_l_value = $l_value; } $clause = array(); for ($e=$c; $e <= $right_value; $e++) if (!$and_mode || $e != $c) $clause[] = $e; $text .= "

"; //$highlighted_positions = get_clause($c); //$highlighted_positions[] = $l_value; //$text .= print_sentence_highlighted($sentence,array_merge(array($l_value),get_clause($sentence,$c))); //if ($and_mode) // $l_value = $sentence[$l_value]['l_value']; $text .= print_sentence_highlighted($sentence,array_merge(array($highlighted_l_value),$clause)); $text .= "

"; } } } return $text; } function get_all_passive_participles(&$sentence) { $passive_participles = array(); for ($c=0; $c < sizeof($sentence); $c++) if (isset($sentence[$c]['passive_participle'])) $passive_participles[] = $c; return $passive_participles; } function print_sentence_alternatives_verb($sentence) { $text = ""; $passive_participles = get_all_passive_participles($sentence); foreach ($passive_participles as $verb_position) { $text .= "

"; for ($c=0; $c < sizeof($sentence); $c++) { if (isset($sentence[$c]['passive_participle'])) { if ($c==$verb_position) { $text .= ''; $text .= " " . WORD_DID . " "; $text .= get_name_of_word_in_sentence($sentence[$c]) . " "; $text .= ''; } else { $text .= ''; $text .= " " . WORD_WHO . " " . WORD_IS . " "; $text .= get_name_of_word_in_sentence($sentence[$c]) . " "; $text .= ''; } } else $text .= get_name_of_word_in_sentence($sentence[$c]) . " "; } $text .= "

"; } return $text; } function print_sentence_highlighted($sentence,$position_table) { $text = ""; for ($c=0; $c < sizeof($sentence); $c++) { if (in_array($c,$position_table)) { //$text .= ""; $text .= ''; $text .= get_name_of_word_in_sentence($sentence[$c]) . " "; $text .= ''; //$text .= ""; } else $text .= get_name_of_word_in_sentence($sentence[$c]) . " "; } return $text; } function get_name_of_word_in_sentence($word_in_sentence) { return $word_in_sentence['raw_word']; } function get_type_of_word_in_sentence($word_in_sentence) { return $word_in_sentence['word'][0]['type']; } function get_selected_word($word_list) { foreach ($word_list as $word) if (isset($word['selected'])) return $word; } function replace_selected_stem_word_by_parent_word(&$word_list) { for ($c=0; $c < sizeof($word_list); $c++) if (isset($word_list[$c]['selected'])) { if (isset($word_list[$c]['parent_id'])) { $word_list[$c]['word_id'] = $word_list[$c]['parent_id']; $word_list[$c]['name'] = $word_list[$c]['parent_name']; } } } function delete_all_unselected_words() { } function get_l_value($word_in_sentence) { if ($word_in_sentence['l_value'] == L_VALUE_END) return array(L_VALUE_END,L_TYPE_END); else return array($word_in_sentence['l_value'],$word_in_sentence['l_type']); /* foreach (array('l_value','m_value','n_value') as $value) if (isset($word_in_sentence[$value])) if (($l_value = $word_in_sentence[$value]) == L_VALUE_END) return array($l_value,'e'); else return array($l_value,substr($value,0,1)); */ } /* function enter_sentence(&$sentence) { //foreach ($sentence as $word) for ($position=0; $position < sizeof($sentence); $position++) { $word = get_selected_word($sentence[$position]['word']); list($position_l_value,$l_type) = get_l_value($word); //$l_word = get_selected_word($sentence[$position_l_value]); if (!isset($sentence['position']['sentence_id']) && ( $position_l_value<0 || isset($sentence['position_l_value']['sentence_id']) ) ) { if ($position_l_value<0) $l_value = 0; else $l_value = $sentence['position_l_value']['sentence_id']; $sql = "INSERT INTO sentences (word_id,l_value,l_type) VALUES (" . $word['word_id'] . "," . $l_value . "," . $l_type . ")"; mysql_query_2($sql); $sentence[$position]['sentence_id'] = mysql_insert_id(); } } } */ function enter_input(&$sentence) { $text = ""; $position = 0; //foreach ($sentence as $word) while (isset_primary_sentence_position($sentence,$position)) { if (is_string_selected($sentence,$position)) $text .= '\"' . $sentence[$position++]['raw_word'] . '\" '; else $text .= $sentence[$position++]['raw_word'] . " "; } list($url) = extract_input_parameters($sentence); if ($url==0) $url = "NULL"; $sql = "INSERT INTO inputs (text,date,url) VALUES (\"" . substr($text,0,-1) . "\",CURRENT_TIMESTAMP,$url)"; mysql_query_2($sql); return mysql_insert_id(); } function add_modus(&$sentence,$position,$modus) { if (isset($sentence[$position]['modus'])) $sentence[$position]['modus'] |= $modus; else $sentence[$position]['modus'] = $modus; } function set_modus(&$sentence,$position) { global $MODUS_BIT,$MODI_LIST; //if (is_verb($sentence[$position]['word'])) { // $modus = 0; foreach ($MODI_LIST as $modus_name) if (isset($sentence[$position][$modus_name])) add_modus($sentence,$position,$MODUS_BIT[$modus_name]); //deby("
add modus: pos=$position,modus=$modus_name");} // $modus |= $MODUS_BIT[$modus_name]; // $sentence[$position]['modus'] = $modus; // echo "
MODUS $modus an POSITION $position"; } //if (duplicate_word($sentence,$position)) // add_modus($sentence,$position,$MODUS_BIT['duplicated_word']); } function encode_sentence(&$sentence) { encode_article($sentence); encode_preposition($sentence); // encode_noun_sequence($sentence,true); // encode_equivalence_relation_be($sentence); for ($position=0; $position < sizeof($sentence); $position++) { //echo print_sentence_detailed($sentence); die(); if ($sentence[$position]['l_type'] != L_TYPE_DROP) set_modus($sentence,$position); } } function encode_article(&$sentence) { for ($position=0; $position < sizeof($sentence); $position++) { if ($sentence[$position]['l_type'] != L_TYPE_DROP) { $raw_word = $sentence[$position]['raw_word']; if ($raw_word==WORD_THE) { $sentence[$sentence[$position]['l_value']]['article_the'] = true; set_l_value_drop($sentence[$position]); } else if ($raw_word==WORD_A || $raw_word==WORD_AN) { $sentence[$sentence[$position]['l_value']]['article_a'] = true; set_l_value_drop($sentence[$position]); } } } } function get_preposition_index(&$sentence,$position) { global $PREPOSITIONS; $raw_word = $sentence[$position]['raw_word']; return get_index($raw_word,$PREPOSITIONS); } function encode_preposition(&$sentence) { for ($position=0; $position < sizeof($sentence); $position++) { if ($sentence[$position]['l_type'] != L_TYPE_DROP && is_preposition_selected($sentence,$position)) { $preposition_index = get_preposition_index($sentence,$position); if ($preposition_index < 0) throw new sentence_exception("programm: preposition unknown",0,$position); $noun_after_preposition = get_child($sentence,$position,M_TYPE); $sentence[$noun_after_preposition]['preposition'] = $preposition_index; copy_l_value_and_type($sentence,$position,$noun_after_preposition); //$sentence[$noun_after_preposition]['l_value'] = $sentence[$position]['l_value']; //$sentence[$noun_after_preposition]['l_type'] = $sentence[$position]['l_type']; set_l_value_drop($sentence[$position]); } } } function encode_noun_sequence(&$sentence,$split_noun_sequence=false) { for ($position=0; $position < sizeof($sentence); $position++) { if ($sentence[$position]['l_type'] == NOUN_TYPE) { list($anchor_noun,$level) = get_anchor_of_noun_sequence($sentence,$position); cluster($sentence,$anchor_noun,$position); if ($split_noun_sequence) { $sentence[$position]['level'] = $level; copy_l_value_and_type($sentence,$anchor_noun,$position); } /* $level = 0; $c = $anchor_noun; while (1) { //$sentence[$c]['level'] = $level; cluster($sentence,$position,$c); //$sentence[$c]['reference_for_cluster_id'] = $position; //copy_l_value_and_type($sentence,$anchor_noun,$c); $c = get_child($sentence,$c,NOUN_TYPE); if ($c==INVALID_POSITION) break; $level++; } */ } } //deby(print_sentence_detailed($sentence)); die(); } function encode_equivalence_relation_be(&$sentence) { for ($position=0; $position < sizeof($sentence); $position++) { if (is_be($sentence[$position]['word'])) { $subject = get_child($sentence,$position,S_TYPE); $object = get_child($sentence,$position,N_TYPE); if ($subject != INVALID_POSITION && $object != INVALID_POSITION && $sentence[$subject]['raw_word'] != WORD_THERE) cluster($sentence,$subject,$object); } } } function cluster(&$sentence,$position,$child) { // if (isset($sentence[$position]['reference_for_cluster_id'])) // $position $sentence[$child]['reference_for_cluster_id'] = $position; } function duplicate_word(&$sentence,$position) { //return (is_noun($sentence[$position]['word']) || is_verb($sentence[$position]['word'])); return ($sentence[$position]['l_type'] != L_TYPE_DROP && !isset($sentence[$position]['reference'])); } function get_referred_position(&$sentence,$position) { if (isset($sentence[$position]['reference'])) return $sentence[$position]['reference']; else return $position; } function remove_superfluent_references(&$sentence) { for ($position=0; $position < sizeof($sentence); $position++) { //if ($sentence[$position]['l_type'] != L_TYPE_DROP) { foreach (array('l_value','reference') as $index) { if (isset($sentence[$position][$index])) { $l_value = $sentence[$position][$index]; if (isset($sentence[$l_value]['reference'])) // ** Achtung wenn auch preposition bei reference!! { $sentence[$position][$index] = $sentence[$l_value]['reference']; //set_l_value_drop($sentence[$l_value]); } } } } } } function get_origin_of_reference(&$sentence,$position,$reference_index='reference') { if (isset($sentence[$position][$reference_index])) return get_origin_of_reference($sentence,$sentence[$position][$reference_index],$reference_index); else return $position; } function determine_cluster_references(&$sentence) { for ($position=0; $position < sizeof($sentence); $position++) if (isset($sentence[$position]['reference'])) { $cluster_point = get_origin_of_reference($sentence,$position); $sentence[$position]['reference_for_cluster_id'] = $cluster_point; } for ($position=0; $position < sizeof($sentence); $position++) { //unset($cluster_point); if (isset($sentence[$position]['reference_for_cluster_id'])) { $cluster_point = get_origin_of_reference($sentence,$position,'reference_for_cluster_id'); $sentence[$cluster_point]['use_cluster_id'] = true; $sentence[$position]['reference_for_cluster_id'] = $cluster_point; } else // if (!isset($cluster_point)) { deby("NUMBER of edges = " . number_of_edges($sentence,$position)); if (number_of_edges($sentence,$position) > 1) $sentence[$position]['use_cluster_id'] = true; } } } function enter_sentence(&$sentence) { check_correctness_of_sentence($sentence); remove_superfluent_references($sentence); //deby( print_sentence_detailed($sentence)); die(); add_location($sentence); encode_sentence($sentence); remove_and($sentence); fusion_double_edges($sentence); determine_cluster_references($sentence); // load_word_information_for_database($sentence); //$graph = load_cluster_words($sentence); // echo print_sentence_detailed($sentence); // print_r($sentence); die(); $input_id = enter_input($sentence); //global $L_VALUE_END; for ($position=0; $position < sizeof($sentence); $position++) { if ($sentence[$position]['l_type'] != L_TYPE_DROP) // && $sentence[$position]['l_value'] != INVALID_POSITION) { /* if (duplicate_word($sentence,$position)) { $word = get_selected_word($sentence[$position]['word']); $sql = "INSERT INTO sentences (word_id) VALUES (" . $word['word_id'] . ")"; mysql_query_2($sql); $sentence[$position]['duplicated_word_id'] = mysql_insert_id(); } */ if ($sentence[$position]['l_value'] != INVALID_POSITION) { $sql = "INSERT INTO sentences () VALUES ()";// (word_id) VALUES (" . $word['word_id'] . ")"; mysql_query_2($sql); $sentence[$position]['sentence_id'] = mysql_insert_id(); } } } for ($position=0; $position < sizeof($sentence); $position++) { if ($sentence[$position]['l_type'] != L_TYPE_DROP) { $l_value = $sentence[$position]['l_value']; if ($l_value != INVALID_POSITION) { //deby("
zurodnung cluster_id: l_value=$l_value, position=$position, sentence_id = " . $sentence[$position]['sentence_id']); if (isset($sentence[$position]['use_cluster_id']) && !isset($sentence[$position]['cluster_id'])) $sentence[$position]['cluster_id'] = $sentence[$position]['sentence_id'] * 2; if (isset($sentence[$l_value]['use_cluster_id']) && !isset($sentence[$l_value]['cluster_id'])) $sentence[$l_value]['cluster_id'] = $sentence[$position]['sentence_id'] * 2 + 1; } } } for ($position=0; $position < sizeof($sentence); $position++) { if ($sentence[$position]['l_type'] != L_TYPE_DROP) { //$l_value = $sentence[$position]['l_value']; $vertex[0] = get_referred_position($sentence,$position); $vertex[1] = $sentence[$position]['l_value']; //get_referred_position($l_value); if ($vertex[0] != INVALID_POSITION && $vertex[1] != INVALID_POSITION) { /*($from_word_id,$from_cluster_word_id,$from_modus,$from_level) = get_word_information_for_database($sentence,$position); ($to_word_id,$to_cluster_word_id,$to_modus,$to_level) = get_word_information_for_database($sentence,$position); */ //list($position_l_value,$l_type) = get_l_value($sentence[$position]); //$l_word = get_selected_word($sentence[$position_l_value]); /* if ($position_l_value == L_VALUE_END) $l_value = $input_id; else $l_value = $sentence[$position_l_value]['sentence_id']; */ //if (isset($sentence[$position]['reference'])) //$word_cluster_id = $sentence[get_referred_position($sentence,$position)]['sentence_id']; /* for ($index=0; $index < 2; $index++) { if (isset($sentence[$vertex[$index]]['use_cluster_id'])) if (!isset($sentence[$vertex[$index]]['cluster_id'])) $sentence[$vertex[$index]]['cluster_id'] = $sentence[$position]['sentence_id'] * 2 + $index; if (isset($sentence[$vertex[$index]]['reference_for_cluster_id'])) $sentence[$vertex[$index]]['cluster_id'] = $sentence[$sentence[$vertex[$index]]['reference_for_cluster_id']]['cluster_id']; }*/ /* if (isset($sentence[$to]['use_cluster_id'])) if (!isset($sentence[$to]['cluster_id'])) $sentence[$to]['cluster_id'] = $sentence[$position]['sentence_id'] * 2 + 1; if (isset($sentence[$to]['reference_for_cluster_id'])) $sentence[$to]['cluster_id'] = $sentence[$sentence[$to]['reference_for_cluster_id']]['cluster_id']; */ //if (isset($sentence)) $sql = "UPDATE sentences SET "; if (isset($sentence[$position]['coordinates'])) //$sql .= vertex_sql_coordinates($sentence,$position) . "," $sql .= "number_0=" . $sentence[$position]['coordinates']['latitude'] . ",number_1=" . $sentence[$position]['coordinates']['longitude'] . ","; else vertex_sql_for_enter_sentence($sentence,$vertex[0],$position,0,$sql); vertex_sql_for_enter_sentence($sentence,$vertex[1],$position,1,$sql); /* . "word_id_0=" . get_selected_word_id($sentence,$from) . ",modus_0=" . get_modus($sentence,$from) . ",level_0=" . get_level($sentence,$from) . ",cluster_id_0=" . $sentence[$from]['cluster_id'] . ",preposition_0='" . chr(get_preposition($sentence,$from,$position)) . "'" . ",word_id_1=" . get_selected_word_id($sentence,$to) . ",modus_1=" . get_modus($sentence,$to) . ",level_1=" . get_level($sentence,$to) . ",cluster_id_1=" . $sentence[$to]['cluster_id'] . ",preposition_1=0" // . get_preposition($sentence,$to) */ $sql .= "l_type='" . $sentence[$position]['l_type'] . "',input_id=" . $input_id . " WHERE sentence_id=" . $sentence[$position]['sentence_id']; mysql_query_2($sql); //$sentence[$position]['sentence_id'] = mysql_insert_id(); } } } } function vertex_sql_noun(&$sentence,$position,$index) { if (is_number($sentence[$position]['word'])) return "number_$index=" . ((float) $sentence[$position]['raw_word']); else return "word_id_$index=" . get_selected_word_id($sentence,$position); } function vertex_sql_preposition(&$sentence,$position,$referring_position,$index,$prefix,$postfix) { if (isset($sentence[$referring_position]['preposition']) && $index==0) return $prefix . "preposition_$index='" . chr(get_preposition($sentence,$position,$referring_position)) . "'" . $postfix; else return ""; } function vertex_sql_cluster_id(&$sentence,$position,$index) { if (isset($sentence[$position]['cluster_id'])) return "cluster_id_$index=" . $sentence[$position]['cluster_id'] . ","; else if (isset($sentence[$position]['reference_for_cluster_id'])) return "cluster_id_$index=" . $sentence[$sentence[$position]['reference_for_cluster_id']]['cluster_id'] . ","; } function vertex_sql_for_enter_sentence(&$sentence,$position,$referring_position,$index,&$sql) { $sql .= vertex_sql_noun($sentence,$position,$index) . ","; if (isset($sentence[$position]['modus'])) $sql .= "modus_$index=" . get_modus($sentence,$position) . ","; if (isset($sentence[$position]['level'])) $sql .= "level_$index=" . get_level($sentence,$position) . ","; $sql .= vertex_sql_cluster_id($sentence,$position,$index); $sql .= vertex_sql_preposition($sentence,$position,$referring_position,$index,"",","); } /* function print_sentence_color_tree($sentence,$l_value=L_VALUE_END,$l_type='m_value',$begin_branch=true) { $text = ""; for ($c=0; $c < sizeof($sentence); $c++) if ($sentence[$c][$l_type]==L_VALUE_END) break; if ($c==sizeof($sentence)) return $text; if ($begin_branch) $text .= "
"; $text .= get_name_of_word_in_sentence($sentence[$c]) . " "; print_sentence_color_tree($sentence,$position); } */ function print_sentence_highlight_decided(&$sentence) { //return ""; $text = "

" . print_sentence_highlight_preposition($sentence) . "

"; //return ""; $text .= "

" . print_sentence_highlight_noun_sequence($sentence) . "

"; //return ""; $text .= "

" . print_sentence_highlight_verb_and_object($sentence) . "

"; return $text; } function print_sentence_highlight_preposition($sentence) { //deby(print_sentence_detailed($sentence)); die(); $text = ""; $color_pointer = 0; $color_table = array("ff0000","00c000","0000ff","c0c000","8000c0","00c0c0","ff8000","60c0ff","00ff00","8040a0"); for ($c=0; $c < sizeof($sentence); $c++) { //if ($sentence[$c]['l_type'] != L_TYPE_DROP) { if (isset($sentence[$c]['decision'])) { //$l_value = get_l_value_skip_reference($sentence,$c); //$sentence[$c]['l_value']; $l_value = $sentence[$c]['decision']; if (!isset($sentence[$l_value]['anchor_color'])) $sentence[$l_value]['anchor_color'] = $color_table[$color_pointer++]; } } } // if (!in_array($l_value,$anchor_list)) // $anchor_list[] = $l_value; for ($c=0; $c < sizeof($sentence); $c++) { if (!isset_primary_sentence_position($sentence,$c)) break; //$decided = isset($sentence[$c]['decision']); $anchor = isset($sentence[$c]['anchor_color']); // $post_a_decided_word = isset($sentence[$c]['m_value']) && isset($sentence[$sentence[$c]['m_value']]['decision']) // || isset($sentence[$c]['n_value']) && isset($sentence[$sentence[$c]['n_value']]['decision']); // $post_a_decided_word = ($sentence[$c]['l_type']==M_TYPE || $sentence[$c]['l_type']==N_TYPE) // && isset($sentence[$sentence[$c]['l_value']]['decision']); //$decided = $decided || $post_a_decided_word; if ($anchor) { $anchor_color = $sentence[$c]['anchor_color']; $text .= "
"; // border:2px solid black;\" >"; } //if ($decided) // || $post_a_decided_word) $decided = false; $cur_pos = $c; //if ($sentence[$c]['l_type'] != L_TYPE_DROP) { while (1) { if ($cur_pos == INVALID_POSITION || isset($sentence[$cur_pos]['reference'])) break; if (isset($sentence[$cur_pos]['decision'])) //if ($c != $cur_pos && isset($sentence[$cur_pos]['anchor_color'])) { // if ($sentence[$cur_pos]['l_value'] == INVALID_POSITION) // break; //$child_color = $sentence[$sentence[$cur_pos]['l_value']]['anchor_color']; //$child_color = $sentence[get_l_value_skip_reference($sentence,$cur_pos)]['anchor_color']; deby("
Lade anchor color: $cur_pos"); $child_color = $sentence[$sentence[$cur_pos]['decision']]['anchor_color']; //$child_color = $sentence[$cur_pos]['anchor_color']; //$text .= ""; $text .= ""; $text .= "
"; $decisions = true; $decided = true; break; } //if (isset($sentence[$cur_pos]['decision'])) // $cur_pos = $sentence[$cur_pos]['decision']; //else if (isset($sentence[$cur_pos]['former_l_value']) && $sentence[$cur_pos]['l_type']==L_TYPE_DROP) //sonst looping bei passiv //is_preposition_selected($sentence,$cur_pos]) $cur_pos = $sentence[$cur_pos]['former_l_value']; else $cur_pos = $sentence[$cur_pos]['l_value']; //get_l_value_skip_reference($sentence,$cur_pos); // } } /* if ($post_a_decided_word) // || $post_a_decided_word) { // if (isset($sentence[$c]['m_value'])) // $child_color = $sentence[$sentence[$sentence[$c]['m_value']]['l_value']]['anchor_color']; // else // $child_color = $sentence[$sentence[$sentence[$c]['n_value']]['l_value']]['anchor_color']; // $child_color = $sentence[$sentence[get_array_value(get_l_value($sentence[$c]),0)]['l_value']]['anchor_color']; $child_color = $sentence[$sentence[$sentence[$c]['l_value']]['l_value']]['anchor_color']; $text .= "
"; } */ if (!$anchor && !$decided) // && !$post_a_decided_word) $text .= "
"; $text .= get_name_of_word_in_sentence($sentence[$c]);// . " "; /* if ($sentence[$c]['l_type']==NOUN_TYPE) $text .= "_"; else $text .= " "; */ if (!$anchor && !$decided) // && !$post_a_decided_word) $text .= "
"; if ($anchor) $text .= '
'; if ($decided) // || $post_a_decided_word) $text .= '
'; } $text .= "
"; if (isset($decisions)) return $text; else return ""; } function determine_last_object(&$sentence,$position) { get_child($sentence,$position); } function print_sentence_highlight_verb_and_object($sentence) { $text = ""; $color_pointer = 0; $color_table = array("ffff00","c00480","2080ff","c000ff","80ffc0","5090c0","ff8000","60c0ff","00ff00","8040a0"); for ($c=0; $c < sizeof($sentence); $c++) { //if ($sentence[$c]['l_type'] != L_TYPE_DROP) { if (isset($sentence[$c]['number_of_objects'])) { if ($sentence[$c]['number_of_objects'] == $sentence[$c]['whole_number_of_objects']) $verb = $c; else $verb = $sentence[$c]['anchor_verb_of_expecting_noun']; $sentence[$verb]['anchor_color'] = $color_table[$color_pointer++]; //list($object,$object_l_type) = determine_last_object($sentence,$verb); //$sentence[$verb]['object_l_type'] = $object_l_type; $sentence[$verb]['verb_decision'] = $c; } } } for ($c=0; $c < sizeof($sentence); $c++) { if (!isset_primary_sentence_position($sentence,$c)) break; /* $anchor = isset($sentence[$c]['anchor_color']); if ($anchor) { $anchor_color = $sentence[$c]['anchor_color']; $text .= "
"; // border:2px solid black;\" >"; } */ $decided = false; $cur_pos = $c; //if ($sentence[$c]['l_type'] != L_TYPE_DROP) { while (1) { //deby(" |cur pos = " . $cur_pos); if ($cur_pos == INVALID_POSITION || isset($sentence[$cur_pos]['reference']) || $sentence[$cur_pos]['l_type'] == L_TYPE_DROP) break; if (isset($sentence[$cur_pos]['anchor_color'])) { if ($cur_pos != $c) { if ($last_type != N_TYPE) break; /* $number_objects = get_number_of_objects($sentence,$cur_pos); if ($number_objects==2 && $last_type != N_TYPE) break; if ($number_objects==1 && $last_type != M_TYPE) break; */ } $child_color = $sentence[$cur_pos]['anchor_color']; $text .= ""; $text .= "
"; $decisions = true; $decided = true; break; } $last_type = $sentence[$cur_pos]['l_type']; if (isset($sentence[$cur_pos]['former_l_value']) && $sentence[$cur_pos]['l_type']==L_TYPE_DROP) $cur_pos = $sentence[$cur_pos]['former_l_value']; else $cur_pos = $sentence[$cur_pos]['l_value']; //get_l_value_skip_reference($sentence,$cur_pos); // } } if (/*!$anchor &&*/ !$decided) $text .= "
"; $text .= get_name_of_word_in_sentence($sentence[$c]);// . " "; if (/*!$anchor &&*/ !$decided) // && !$post_a_decided_word) $text .= "
"; //if ($anchor) // $text .= '
'; if ($decided) $text .= '
'; } $text .= "
"; if (isset($decisions)) return $text; else return ""; } /* function get_l_value(&$sentence,$position) { if (isset($sentence[$position]['m_value'])) return $sentence[$position]['m_value']; if (isset($sentence[$position]['n_value'])) return $sentence[$position]['n_value']; return $sentence[$position]['l_value']; }*/ function get_l_value_skip_reference(&$sentence,$position) { $l_value = $sentence[$position]['l_value']; if (isset($sentence[$l_value]['reference'])) return $sentence[$l_value]['reference']; else return $l_value; } function get_array_value($array,$position) { return $array[$position]; } function try_to_decide_l_value(&$sentence,$position) { //return; $m_value = $sentence[$position]['l_value']; //get_l_value($sentence,$position); //$word_id_r_value = get_array_value(get_selected_word($sentence[$position]['word']),'word_id'); for ($c=0; $c < sizeof($sentence[$m_value]['l_value']); $c++) { $l_value = $sentence[$m_value]['l_value'][$c]; deby( "
" . $l_value . " " . $m_value . " " . $position); /* $word_id_m_value = get_array_value(get_selected_word($sentence[$m_value]['word']),'word_id'); $word_id_l_value = get_array_value(get_selected_word($sentence[$l_value]['word']),'word_id'); $result = query_small_sentence($word_id_l_value,$word_id_m_value,$word_id_r_value); */ /*$result = query_small_sub_sentence($sentence,array($l_value,$m_value,$position)); $number_of_occurences[$c] = mysql_num_rows($result); */ $number_of_occurences[$c] = query_statistics_edges_with_preposition($sentence,$l_value,$m_value,$position); deby( " occurences: " . $number_of_occurences[$c]); } return try_to_decide_by_probability($number_of_occurences); } function try_to_decide_verb(&$sentence) { $passive_participles = get_all_passive_participles($sentence); if (sizeof($passive_participles)==1) return $passive_participles[0]; for ($c=0; $c < sizeof($passive_participles); $c++) { $sub_sentence = get_sub_sentence_subject_predicate_object($sentence,$passive_participles[$c]); if ($sub_sentence[$passive_participles[$c]]['l_value'] != INVALID_POSITION) $subject_factor = 1; else $subject_factor = 1; deby(print_sentence_detailed($sub_sentence));// die(); //$result = query_sentence($sub_sentence); //$number_of_occurences[$c] = mysql_num_rows($result) * $subject_factor; $number_of_occurences[$c] = statistically_query_sentence($sub_sentence) * $subject_factor; deby( " occurences verb: " . $number_of_occurences[$c]); } //print_r($number_of_occurences); if (($index_of_lowest_probability = try_to_decide_by_low_probability($number_of_occurences)) != INVALID_POSITION) { deby(" - low-prob - " . $index_of_lowest_probability); //die(); return $passive_participles[$index_of_lowest_probability]; } else return INVALID_POSITION; } function try_to_determine_number_of_objects(&$sentence,$anchor_verb_of_expecting_noun,$anchor_verb,$object,$number_of_objects) { foreach (array($anchor_verb_of_expecting_noun,$anchor_verb) as $verb) { $word_id = get_array_value(get_selected_word($sentence[$verb]['word']),'word_id'); $objects = query_number_of_objects_statistics_of_verb($word_id); $probability[$verb] = relative_proportion($objects); list($max_probability[$verb],$max_objects[$verb]) = get_max_position($probability[$verb]); $probability[$verb][] = 0; } if (isset($sentence[$anchor_verb]['passive'])) $passive_correction=1; else $passive_correction=0; //print_r($probability); deby(" objects=$number_of_objects"); $first_variant = $probability[$anchor_verb_of_expecting_noun][2] * $probability[$anchor_verb][$number_of_objects-1+$passive_correction]; $second_variant = $probability[$anchor_verb_of_expecting_noun][1] * $probability[$anchor_verb][$number_of_objects+$passive_correction]; if ($first_variant==0 && $second_variant==0) return -1; if ($second_variant==0 || $first_variant/$second_variant > THRESHOLD_FACTOR_FOR_NUMBER_OF_OBJECTS_DECISION) return $number_of_objects-1; if ($first_variant==0 || $second_variant/$first_variant > THRESHOLD_FACTOR_FOR_NUMBER_OF_OBJECTS_DECISION) return $number_of_objects; return -1; /* $word_id_second_verb = get_array_value(get_selected_word($sentence[$anchor_verb]['word']),'word_id'); $number_objects_first_verb = query_number_of_objects_statistics_of_verb($word_id_first_verb); $number_objects_second_verb = query_number_of_objects_statistics_of_verb($word_id_second_verb); */ } function try_to_decide_by_low_probability($number_of_occurences) { //$probability = relative_proportion($number_of_occurences); $number_of_occurences_sorted = $number_of_occurences; sort($number_of_occurences_sorted); if ($number_of_occurences_sorted[0] < THRESHOLD_LOW_PROBABILITY_FOR_DECISION * $number_of_occurences_sorted[1]) { list($min_value,$min_position) = get_low_position($number_of_occurences); return $min_position; } else return INVALID_POSITION; } function try_to_decide_by_probability($number_of_occurences) { $probability = relative_proportion($number_of_occurences); foreach ($probability as $x) deby( " proba:" . $x); list($max_probability,$position_of_max_probability) = get_max_position($probability); // = $position_of_max_probability = in_array(max($probability),$probability); deby( " --pos_max_probability: " . $position_of_max_probability); if ($max_probability >= THRESHOLD_PROBABILITY_FOR_DECISION) return $position_of_max_probability; else return INVALID_POSITION; } function query_small_sub_sentence(&$sentence,$positions) { for ($c=0; $c < sizeof($positions); $c++) { $sub_sentence[$c] = $sentence[$positions[$c]]; $sub_sentence[$c]['l_value'] = $c-1; $sub_sentence[$c]['l_type'] = L_TYPE; } set_l_value_end($sub_sentence[0]); $sub_sentence[2]['l_type'] = M_TYPE; return query_sentence($sub_sentence); /* $sql = "SELECT l.sentence_id FROM sentences l,sentences m,sentences r WHERE l.word_id=$l_value AND r.word_id = $r_value AND m.word_id=$m_value AND l.sentence_id=m.l_value AND m.sentence_id=r.l_value AND m.l_type='l' AND r.l_type='m'"; return mysql_query_2($sql); */ } function relative_proportion($array) { $sum = array_sum($array); foreach ($array as $number) if ($sum>0) $relative_proportion[] = $number/$sum; else $relative_proportion[] = 0; return $relative_proportion; } function get_low_position($array) { for ($c=0; $c < sizeof($array); $c++) $array[$c] *= (-1); //print_r($array); return get_max_position($array); } function get_max_position($array) { $max_value = $array[0]-1; for ($c=0; $c < sizeof($array); $c++) { if ($array[$c] >= $max_value) { $max_value = $array[$c]; $max_position = $c; } } return array($max_value,$max_position); } /* function get_highest_level(&$sentence) { foreach ($sentence as $word) if (isset($word['level'])) $levels[] = $word['level']; if (isset($levels)) return min($levels); else return 0; }*/ function set_and_get_variable_point(&$sentence,$position,&$variable_position_list) { if (is_variable($sentence[$position]['word'])) { $raw_word = $sentence[$position]['raw_word']; if (isset($variable_position_list[$raw_word])) { $cluster_id = $sentence[$variable_position_list[$raw_word]]['cluster_id']; $cluster_id_position = $sentence[$variable_position_list[$raw_word]]['cluster_id_position']; return array(true,false,$cluster_id,$cluster_id_position); } else { $variable_position_list[$raw_word] = $position; return array(true,true,0,0); } } return array(false,false,0,0); } function query_sentence(&$sentence /* &$ */ /*,$position=0,$end_position=INVALID_POSITION*/ ,$consider_modus=false/*$negative_query=false*/, $search_options=array()) /* $consider_level=false,$unbound_level_start=true,$consider_article=false,$consider_tense=false, $consider_modal_verb=false,$identify_general_noun_locally=false,$identify_verb_locally=false)*/ { remove_superfluent_references($sentence); encode_sentence($sentence); remove_and($sentence); deby("QUERING " . print_sentence_detailed($sentence)); //echo print_sentence_detailed($sentence); die(); /* if ($negative_query) { $relative_l_value__word_id = get_word_id(SYNTHETICAL_WORD__RELATIVE_L_VALUE); } */ // $length = sizeof($sentence)-$position; //$consider_modus = false; //$highest_level = get_highest_level($sentence); //$highest_level_position = INVALID_POSITION; mysql_query_2("SET SQL_BIG_SELECTS=1"); $sql = ""; $sql_tables = ""; /* for ($c=0; $c < sizeof($sentence); $c++) { if ($sentence[$c]['l_type'] != L_TYPE_DROP && $sentence[$c]['l_value'] != INVALID_POSITION) { if (!isset($first_position)) $first_position = $c; else $sql .= ","; $sql .= "sentences l$c"; } } */ list($highest_level,$highest_level_position,$highest_level_index,$highest_level_leftright) = get_highest_level($sentence); $variable_position_list = array(); for ($c=0; $c < sizeof($sentence); $c++) { if ($sentence[$c]['l_type'] != L_TYPE_DROP && $sentence[$c]['l_value'] != INVALID_POSITION) { if (!isset($first_position)) $first_position = $c; else $sql_tables .= ","; $sql_tables .= "sentences l$c"; $vertex[0] = get_referred_position($sentence,$c); $vertex[1] = $sentence[$c]['l_value']; for ($index=0; $index < 2; $index++) { $position = $vertex[$index]; list($variable,$new_variable,$variable_cluster_id,$variable_cluster_id_position) = set_and_get_variable_point($sentence,$position,$variable_position_list); if (isset($sentence[$position]['cluster_id']) && !isset($search_options['detach_clusters'])) { $cluster_id = $sentence[$position]['cluster_id']; $cluster_id_position = $sentence[$position]['cluster_id_position']; if ( (is_general_noun_selected($sentence,$position) && isset($search_options['identify_general_nouns_locally'])) || (is_verb_selected($sentence,$position) && isset($search_options['identify_verbs_locally'])) ) { if ($variable) $sql .= "l$c.word_id_$index=l$variable_cluster_id.word_id_$variable_cluster_id_position AND "; else //$sql .= "l$c.word_id_$index=" . get_selected_word_id($sentence,$position) . " AND "; $sql .= "l$c." . vertex_sql_noun($sentence,$position,$index) . " AND "; if ( !(isset($identify_input_id[$c][$cluster_id]) || isset($identify_input_id[$cluster_id][$c])) ) $sql .= "l$c.input_id=l$cluster_id.input_id AND "; $identify_input_id[$c][$cluster_id] = true; } else { $sql .= "l$c.cluster_id_$index=l$cluster_id.cluster_id_$cluster_id_position AND "; } } else { $sentence[$position]['cluster_id'] = $c; $sentence[$position]['cluster_id_position'] = "$index"; if (false && is_noun_selected($sentence,$position) && (!$variable || isset($search_options['use_clusters_for_variables']))) { $word_table_name = "w$index" . "_"; $sql_tables .= ",sentences $word_table_name$c"; if ($variable) { if (!$new_variable) { // $sql_tables .= ",sentences w$variable_cluster_id_position" . "_$variable_cluster_id"; // $word_table_name = "w$index" . "_"; // $sql_tables .= ",sentences $word_table_name$c"; $variable_word_table_name = "w$variable_cluster_id_position" . "_$variable_cluster_id"; $sql .= "("; for ($i=0; $i < 2; $i++) for ($j=0; $j < 2; $j++) { $sql .= "(" . "$word_table_name$c.cluster_id_$i=l$c.cluster_id_$index" . " AND $word_table_name$c.word_id_$i =$variable_word_table_name.word_id_$j" . " AND $variable_word_table_name.cluster_id_$j =l$variable_cluster_id.cluster_id_$variable_cluster_id_position)"; if (!($i==1 && $j==1)) $sql .= " OR "; } $sql .= ") AND "; } } else { // $word_table_name = "w$index" . "_"; // $sql_tables .= ",sentences $word_table_name$c"; //$sql .= "(" . vertex_sql_noun_or_variable($sentence,$vertex[$index],$index,$c,$variable_position_list,"l") . " OR " $sql .= "((" . "$word_table_name$c." . vertex_sql_noun($sentence,$position,0) . " AND $word_table_name$c.cluster_id_0=l$c.cluster_id_$index)" . " OR (" . "$word_table_name$c." . vertex_sql_noun($sentence,$position,1) . " AND $word_table_name$c.cluster_id_1=l$c.cluster_id_$index)) AND "; } } else if ($variable) { if (!$new_variable) $sql .= "l$c.word_id_$index=l$variable_cluster_id.word_id_$variable_cluster_id_position AND "; } else $sql .= "l$c." . vertex_sql_noun($sentence,$position,$index) . " AND "; //vertex_sql_noun_or_variable($sentence,$position,$index,$c,$variable_position_list,"l") . " AND "; //$sql .= "l$c." . vertex_sql_noun($sentence,$vertex[$index],$index) . " AND "; //$sql .= "l$c.word_id_$index=" . get_selected_word_id($sentence,$vertex[$index]) . " AND "; if (isset($sentence[$position]['modus']) && $consider_modus) $sql .= "l$c.modus_$index=" . get_modus($sentence,$position) . " AND "; if (isset($sentence[$position]['level']) && !isset($search_options['ignore_level'])) if (isset($search_options['allow_level_shift'])) $sql .= "l$c.level_$index=" . get_level($sentence,$position) . "+l$highest_level_index.level_$highest_level_leftright AND "; else $sql .= "l$c.level_$index=" . get_level($sentence,$position) . " AND "; //if (isset($sentence[$vertex[$index]]['preposition']) && $index==0) //if (($preposition = vertex_sql_preposition($sentence,$vertex[$index],$c,$index)) != "") //if ($index==0 && ($preposition = get_preposition($sentence,$vertex[$index],$c)) ) // $sql .= "l$c.preposition_$index='" . chr($preposition) . "' AND "; } if (!isset($search_options['ignore_preposition'])) $sql .= vertex_sql_preposition($sentence,$position,$c,$index,"l$c."," AND "); } /* if (isset($sentence[$to]['cluster_id'])) { $cluster_id = $sentence[$to]['cluster_id']; $cluster_id_position = $sentence[$to]['cluster_id_position']; $sql .= "l$c.cluster_id_1=l$cluster_id.cluster_id_$cluster_id_position AND "; } else { $sentence[$to]['cluster_id'] = $c; $sentence[$to]['cluster_id_position'] = "1"; $sql .= "l$c.word_id_1=" . get_selected_word_id($sentence,$to) . " AND "; if (isset($sentence[$to]['modus']) && $consider_modus) $sql .= "l$c.modus_1=" . get_modus($sentence,$to) . " AND "; if (isset($sentence[$to]['level']) && $consider_level) if ($unbound_level_start) $sql .= "l$c.level_1=" . get_level($sentence,$to) . "+l$highest_level_index.level_$highest_level_leftright AND "; else $sql .= "l$c.level_1=" . get_level($sentence,$to); } */ $sql .= "l$c.l_type='" . $sentence[$c]['l_type'] . "' AND "; } } $sql = substr($sql,0,-5); if (!isset($first_position)) return query_one_word_sentence($sentence,$consider_modus,$search_options); //$consider_level,$unbound_level_start); $sql = "SELECT l$first_position.sentence_id AS sentence_id, l$first_position.input_id AS input_id, l$first_position.l_type AS l_type FROM " . $sql_tables .= " WHERE " . $sql; return mysql_query_2($sql); } function query_sentence_v3(&$sentence /* &$ */ /*,$position=0,$end_position=INVALID_POSITION*/ ,$consider_modus=false/*$negative_query=false*/, $search_options=array()) /* $consider_level=false,$unbound_level_start=true,$consider_article=false,$consider_tense=false, $consider_modal_verb=false,$identify_general_noun_locally=false,$identify_verb_locally=false)*/ { remove_superfluent_references($sentence); encode_sentence($sentence); remove_and($sentence); deby("QUERING " . print_sentence_detailed($sentence)); //echo print_sentence_detailed($sentence); die(); /* if ($negative_query) { $relative_l_value__word_id = get_word_id(SYNTHETICAL_WORD__RELATIVE_L_VALUE); } */ // $length = sizeof($sentence)-$position; //$consider_modus = false; //$highest_level = get_highest_level($sentence); //$highest_level_position = INVALID_POSITION; mysql_query_2("SET SQL_BIG_SELECTS=1"); $sql = ""; $sql_tables = ""; /* for ($c=0; $c < sizeof($sentence); $c++) { if ($sentence[$c]['l_type'] != L_TYPE_DROP && $sentence[$c]['l_value'] != INVALID_POSITION) { if (!isset($first_position)) $first_position = $c; else $sql .= ","; $sql .= "sentences l$c"; } } */ list($highest_level,$highest_level_position,$highest_level_index,$highest_level_leftright) = get_highest_level($sentence); $variable_position_list = array(); for ($c=0; $c < sizeof($sentence); $c++) { if ($sentence[$c]['l_type'] != L_TYPE_DROP && $sentence[$c]['l_value'] != INVALID_POSITION) { if (!isset($first_position)) $first_position = $c; else $sql_tables .= ","; $sql_tables .= "sentences l0_$c,sentences l1_$c"; $vertex[0] = get_referred_position($sentence,$c); $vertex[1] = $sentence[$c]['l_value']; //$sql .= "l0_$c.sentence_id=l1_$c.sentence_id AND "; $sql .= "(l0_$c.cluster_id_0=l1_$c.cluster_id_0 OR l0_$c.cluster_id_1=l1_$c.cluster_id_0) AND "; for ($index=0; $index < 2; $index++) { $position = $vertex[$index]; list($variable,$new_variable,$variable_cluster_id,$variable_cluster_id_position) = set_and_get_variable_point($sentence,$position,$variable_position_list); if (isset($sentence[$position]['cluster_id']) && !isset($search_options['detach_clusters'])) { $cluster_id = $sentence[$position]['cluster_id']; $cluster_id_position = $sentence[$position]['cluster_id_position']; if ( (is_general_noun_selected($sentence,$position) && isset($search_options['identify_general_nouns_locally'])) || (is_verb_selected($sentence,$position) && isset($search_options['identify_verbs_locally'])) ) { if ($variable) $sql .= "l$c.word_id_$index=l$variable_cluster_id.word_id_$variable_cluster_id_position AND "; else //$sql .= "l$c.word_id_$index=" . get_selected_word_id($sentence,$position) . " AND "; $sql .= "l$c." . vertex_sql_noun($sentence,$position,$index) . " AND "; if ( !(isset($identify_input_id[$c][$cluster_id]) || isset($identify_input_id[$cluster_id][$c])) ) $sql .= "l$c.input_id=l$cluster_id.input_id AND "; $identify_input_id[$c][$cluster_id] = true; } else { $sql .= "l$index" . "_$c.cluster_id_$index=l$cluster_id_position" . "_$cluster_id.cluster_id_$cluster_id_position AND "; // $sql .= "l$index" . "_$c.cluster_id_$index=l$cluster_id_position" . "_$cluster_id.cluster_id_$cluster_id_position AND "; // $sql .= "(l0" . "_$c.cluster_id_$index=l0" . "_$cluster_id.cluster_id_$cluster_id_position AND "; // $sql .= "l1" . "_$c.cluster_id_$index=l1" . "_$cluster_id.cluster_id_$cluster_id_position) )"; } } else { $sentence[$position]['cluster_id'] = $c; $sentence[$position]['cluster_id_position'] = "$index"; if (false && is_noun_selected($sentence,$position) && (!$variable || isset($search_options['use_clusters_for_variables']))) { $word_table_name = "w$index" . "_"; $sql_tables .= ",sentences $word_table_name$c"; if ($variable) { if (!$new_variable) { // $sql_tables .= ",sentences w$variable_cluster_id_position" . "_$variable_cluster_id"; // $word_table_name = "w$index" . "_"; // $sql_tables .= ",sentences $word_table_name$c"; $variable_word_table_name = "w$variable_cluster_id_position" . "_$variable_cluster_id"; $sql .= "("; for ($i=0; $i < 2; $i++) for ($j=0; $j < 2; $j++) { $sql .= "(" . "$word_table_name$c.cluster_id_$i=l$c.cluster_id_$index" . " AND $word_table_name$c.word_id_$i =$variable_word_table_name.word_id_$j" . " AND $variable_word_table_name.cluster_id_$j =l$variable_cluster_id.cluster_id_$variable_cluster_id_position)"; if (!($i==1 && $j==1)) $sql .= " OR "; } $sql .= ") AND "; } } else { // $word_table_name = "w$index" . "_"; // $sql_tables .= ",sentences $word_table_name$c"; //$sql .= "(" . vertex_sql_noun_or_variable($sentence,$vertex[$index],$index,$c,$variable_position_list,"l") . " OR " $sql .= "((" . "$word_table_name$c." . vertex_sql_noun($sentence,$position,0) . " AND $word_table_name$c.cluster_id_0=l$index" . "_$c.cluster_id_$index)" . " OR (" . "$word_table_name$c." . vertex_sql_noun($sentence,$position,1) . " AND $word_table_name$c.cluster_id_1=l$index" . "_$c.cluster_id_$index)) AND "; } } else if ($variable) { if (!$new_variable) $sql .= "l$index" . "_$c.word_id_$index =l$variable_cluster_id_position" . "_$variable_cluster_id.word_id_$variable_cluster_id_position AND "; } else { $sql .= "l$index" . "_$c." . vertex_sql_noun($sentence,$position,$index) . " AND "; // $sql .= "l1" . "_$c." . vertex_sql_noun($sentence,$position,$index) . " AND "; } //vertex_sql_noun_or_variable($sentence,$position,$index,$c,$variable_position_list,"l") . " AND "; //$sql .= "l$c." . vertex_sql_noun($sentence,$vertex[$index],$index) . " AND "; //$sql .= "l$c.word_id_$index=" . get_selected_word_id($sentence,$vertex[$index]) . " AND "; if (isset($sentence[$position]['modus']) && $consider_modus) $sql .= "l$c.modus_$index=" . get_modus($sentence,$position) . " AND "; if (isset($sentence[$position]['level']) && !isset($search_options['ignore_level'])) if (isset($search_options['allow_level_shift'])) $sql .= "l$index" . "_$c.level_$index=" . get_level($sentence,$position) . "+l$highest_level_leftright" . "_$highest_level_index.level_$highest_level_leftright AND "; else $sql .= "l$index" . "_$c.level_$index=" . get_level($sentence,$position) . " AND "; //if (isset($sentence[$vertex[$index]]['preposition']) && $index==0) //if (($preposition = vertex_sql_preposition($sentence,$vertex[$index],$c,$index)) != "") //if ($index==0 && ($preposition = get_preposition($sentence,$vertex[$index],$c)) ) // $sql .= "l$c.preposition_$index='" . chr($preposition) . "' AND "; } if (!isset($search_options['ignore_preposition'])) { //$sql .= vertex_sql_preposition($sentence,$position,$c,$index,"l0" . "_$c."," AND "); $sql .= vertex_sql_preposition($sentence,$position,$c,$index,"l1" . "_$c."," AND "); } } /* if (isset($sentence[$to]['cluster_id'])) { $cluster_id = $sentence[$to]['cluster_id']; $cluster_id_position = $sentence[$to]['cluster_id_position']; $sql .= "l$c.cluster_id_1=l$cluster_id.cluster_id_$cluster_id_position AND "; } else { $sentence[$to]['cluster_id'] = $c; $sentence[$to]['cluster_id_position'] = "1"; $sql .= "l$c.word_id_1=" . get_selected_word_id($sentence,$to) . " AND "; if (isset($sentence[$to]['modus']) && $consider_modus) $sql .= "l$c.modus_1=" . get_modus($sentence,$to) . " AND "; if (isset($sentence[$to]['level']) && $consider_level) if ($unbound_level_start) $sql .= "l$c.level_1=" . get_level($sentence,$to) . "+l$highest_level_index.level_$highest_level_leftright AND "; else $sql .= "l$c.level_1=" . get_level($sentence,$to); } */ //$sql .= "l0_$c.l_type='" . $sentence[$c]['l_type'] . "' AND "; $sql .= "l1_$c.l_type='" . $sentence[$c]['l_type'] . "' AND "; } } $sql = substr($sql,0,-5); if (!isset($first_position)) return query_one_word_sentence($sentence,$consider_modus,$search_options); //$consider_level,$unbound_level_start); $sql = "SELECT l0_$first_position.sentence_id AS sentence_id, l0_$first_position.input_id AS input_id, l0_$first_position.l_type AS l_type FROM " . $sql_tables .= " WHERE " . $sql; return mysql_query_2($sql); } function answer_question(&$sentence) { // encode_sentence($sentence); // remove_superfluent_references($sentence); $result = query_sentence($sentence,false,$_SESSION['search_options']); /*['ignore_level'], $_SESSION['search_options']['allow_level_shift'], false,false,false, $_SESSION['search_options']['identify_general_nouns_'],); */ // query_sentence($sentence,0,INVALID_POSITION,true); if ($result && mysql_num_rows($result) > 0) { $text = "

Findings:

"; $text .= "";// border=\"1\" margin=\"2\" >"; $c=0; $input_ids = array(); while (($row = mysql_fetch_array($result)) && $c++ < 150) { //$sentence_start = seek_sentence_start($row); //deby("
Finding $c"); //list($input_id,$sentence_text,$url) = get_input_text_of_sentence($row); $input_row = get_input_text_of_sentence($row); $input_id = $input_row['input_id']; if (in_array($input_id,$input_ids)) $c--; else { $input_ids[] = $input_id; //debug: show tree: //list($tree,$sentence_text) = read_sentence_tree($row); //$url_text = get_array_value(query_word_by_id($input_row['url']),'name'); $url_text = get_url_text_of_input($input_row); add_html_reference_to_url($sentence_text); //list($tree,$sentence_text) = read_sentence_tree($sentence_start); $text .= "" . "" . "" . ""; } } return /*"

yes

" .*/ $text . "
"; if ($url_text == "") $text .= $input_row['text']; else { $url_text = check_url($url_text); $text .= "" . $input_row['text'] . ""; } $text .= "deletealter
"; } else return "

no result

"; } function query_sentence_row($sentence_id) { $sql = "SELECT * FROM sentences WHERE sentence_id=$sentence_id"; $result = mysql_query_2($sql); return mysql_fetch_array($result); } function query_sentence_childs($sentence_id) { $sql = "SELECT * FROM sentences WHERE l_value=$sentence_id"; return mysql_query_2($sql); // return mysql_fetch_array($result); } function query_word($word) { $sql = "SELECT * FROM words WHERE name='$word'"; return mysql_query_2($sql); /* $sql = "SELECT * FROM words WHERE word_id=$word_id"; $result = mysql_query_2($sql); return mysql_fetch_array($result); */ } /* function seek_sentence_start($sentence_id) { while (1) { if ($row=query_sentence_row($sentence_id)) { if ($row['l_type']==L_TYPE_END) return $row; $sentence_id = $row['l_value']; } else return false; } } */ function seek_sentence_start($sentence_row) { while (1) { if ($sentence_row['l_type']==L_TYPE_END) return $sentence_row; $sentence_row = query_sentence_row($sentence_row['l_value']); } } function read_sentence_tree($sentence_row) { return ""; $text = ""; $tree['row'] = $sentence_row; $tree['word'] = query_word_by_id($sentence_row['word_id']); //$text .= $tree['word']['name'] . " ( "; $text .= $tree['word']['name'] . "-" . $sentence_row['l_type'] . "( "; $result_childs = query_sentence_childs($sentence_row['sentence_id']); while ($child = mysql_fetch_array($result_childs)) { list($sub_tree,$sub_text) = read_sentence_tree($child); $tree['child'][] = $sub_tree; $text .= $sub_text; } $text .= " ) "; return array($tree,$text); } /* function print_sentence_tree($tree) { $text = ""; }*/ function get_url_text_of_input($input_row) { if (!$input_row['url']) return ""; return get_array_value(query_word_by_id($input_row['url']),'name'); } function get_input_text_of_sentence($sentence_row) { $input_id = $sentence_row['input_id']; $row = get_input_row($input_id); return $row; return array($input_id,$row['text'],query_word_by_id($row['url'])); $sentence_start = seek_sentence_start($sentence_row); if ($input_id = $sentence_start['l_value']) return get_array_value(get_input_row($input_id),'text'); else { list($tree,$text) = read_sentence_tree($sentence_row); return $text; } } function get_input_row($input_id) { $sql = "SELECT * FROM inputs WHERE input_id=$input_id"; return mysql_fetch_array(mysql_query_2($sql)); } function add_word_to_sentence(&$sentence,$word,$select_word=false) { $position = sizeof($sentence); $found_words = get_word($word); if ($select_word && sizeof($found_words)==1) $found_words[0]['selected'] = true; $sentence[$position] = array('word' => $found_words, 'raw_word' => $word); return $position; } function add_reference_word_to_sentence(&$sentence,$reference,$l_value=INVALID_POSITION,$l_type=L_TYPE_END) { $position = add_word_to_sentence($sentence,SYNTHETICAL_WORD_REFERENCE,true); $sentence[$position]['reference'] = $reference; $sentence[$position]['l_value'] = $l_value; $sentence[$position]['l_type'] = $l_type; return $position; } function isset_primary_sentence_position(&$sentence,$position) { if (isset($sentence[$position]) && !is_synthetical_word($sentence[$position]['word'])) // !isset($sentence[$position]['primary_sentence_stop_marker'])) return true; else return false; } function get_primary_sentence(&$sentence) { for ($c=0; $c < sizeof($sentence); $c++) if (!isset_primary_sentence_position($sentence,$c)) break; return array_slice($sentence,0,$c); } function delete_synthetical_words(&$sentence) { for ($c=sizeof($sentence); --$c >=0; ) if (!isset_primary_sentence_position($sentence,$c)) unset($sentence[$c]); } /* ALT: function mark_l_value_relative(&$sentence,$position) { $relative_pos = add_word_to_sentence($sentence,SYNTHETICAL_WORD__RELATIVE_L_VALUE,true); $sentence[$relative_pos]['l_value'] = $position; $sentence[$relative_pos]['l_type'] = L_TYPE; }*/ function glossary_maintenance(&$sentence) { //output(work_word($sentence[0]['raw_word'])); $word = $sentence[0]['raw_word']; $text = "

Information about the word \"$word\"

"; $text = "

These are the entries in the word table

"; $text .= print_word_of_word_table($word); $text .= "

These are the possible interpretations

"; //"

So the word may be interpreted"; $text .= list_word($sentence,0); //$text .= ""; $text .= "

Enter here an additional version if necessary

"; //Enter here a new instance if necessary

"; $text .= open_classify_words_form(); $text .= radio_buttons_for_classifying_word($word,'word0'); $text .= close_classify_words_form(); $_SESSION['unknown_words'] = 1; $_SESSION['input'] = $word; output($text); return $error = false; } function exists_word_with_type_and_stem($word_list,$stem,$mask,$type) { foreach ($word_list as $word) //{ echo "

" . /*clear_text_word_type(*/$word['type'] ." ". $mask . " " .( $word['type'] & $mask) ." " . (8352 & 8224) ."

"; if (($word['type'] & $mask)==$type && $word['name']==$stem) return true; //} return false; } function enter_new_words(&$_post) { for ($c=0; $c < $_SESSION['unknown_words']; $c++) { if (isset($_post['word' . $c])) { //$stem_id = 0; $value = explode(":",$_post['word' . $c]); if (sizeof($value)>2) { list($word,$type,$index_stem,$mask_stem_type,$stem_type,$new_stem_type) = $value; $type = (int) $type; $mask_stem_type = (int) $mask_stem_type; $stem_type = (int) $stem_type; $new_stem_type = (int) $new_stem_type; $stem = $_post[$index_stem]; //if ($stem) { $row_stem = search_word_in_word_table($stem,$mask_stem_type,$stem_type); if (!$row_stem) { insert_new_word_in_word_table($stem,$new_stem_type); $stem_id = mysql_insert_id(); } else { output("

Stem already exists.

"); $stem_id = $row_stem['word_id']; } deby( "
stem_id = $stem_id"); $word_list = get_word($word); if (!exists_word_with_type_and_stem($word_list,$stem,$type,$type)) //{ echo "
stem, type = $stem," . clear_text_word_type($type); die(); insert_new_word_in_word_table($word,$type,$stem_id); //} } } else { list($word,$type) = $value; $type = (int) $type; $word_list = get_word($word); if (!$word_exists = exists_word_with_type_and_stem($word_list,$word,$type,$type)) insert_new_word_in_word_table($word,$type); else output("

Word already exists.

"); } /* // does_exist_word_in_word_table(); $row_word = search_word_in_word_table($value[0],-1,$value[1]); if (!$row_word) { if (sizeof($value)>2) { echo $stem = $_post[$value[2]]; if ($stem) { $row_stem = search_word_in_word_table($stem,$value[3],$value[4]); if (!$row_stem) { insert_new_word_in_word_table($stem,$value[5]); $stem_id = mysql_insert_id(); } else $stem_id = $row_stem['word_id']; echo "
stem_id = $stem_id"; insert_new_word_in_word_table($value[0],$value[1],$stem_id); } } else insert_new_word_in_word_table($value[0],$value[1]); } else output("

Entry of word already exists.

"); */ } } } function deby_die(&$sentence) { deby(print_sentence_detailed($sentence)); die(); } function deby($text) { global $debug; if ($debug) echo $text; } function check_correctness_of_sentence(&$sentence) { for ($c=0; $c < sizeof($sentence); $c++) if (!isset($sentence[$c]['l_value']) || !isset($sentence[$c]['l_type'])) throw new sentence_exception("such sentence constructions are still not allowed",0,$c); } function get_last_passive_participle(&$sentence,$position) { for ($c=$position; $c >= 0; $c--) if (isset($sentence[$c]['passive_participle'])) return $c; return INVALID_POSITION; } function get_sub_sentence_subject_predicate_object(&$sentence,$position) { $position_list[] = $position; $position_list[] = $sentence[$position]['l_value']; $position_list[] = get_child($sentence,$position,M_TYPE); $position_list[] = get_child($sentence,$position,N_TYPE); /* $position_list[] = $position; $position_list[] = skip_reference_word($sentence,$sentence[$position]['l_value']); $position_list[] = skip_reference_word($sentence,get_child($sentence,$position,M_TYPE)); $position_list[] = skip_reference_word($sentence,get_child(get_child($sentence,$position,N_TYPE)); */ // remove_refernce_words($sentence,$position_list); return pick_sub_sentence($sentence,$position_list); } /* function skip_reference_word(&$sentence,$position) { if (isset($sentence[$position]['reference'])) return $sentence[$position]['reference']; else return $position; }*/ /* function pick_sub_sentence(&$sentence,$positions) { print_r($positions); $new_position_pointer = 0; for ($c=0; $c < sizeof($positions); $c++) { $sub_sentence[$new_position_pointer] = $sentence[$positions[$c]]; $new_position[$positions[$c]] = $new_position_pointer++; if (isset($sentence[$positions[$c]]['reference'])) { $sub_sentence[$new_position_pointer] = $sentence[$sentence[$positions[$c]]['reference']]; $new_position[$sentence[$positions[$c]]['reference']] = $new_position_pointer++; } } for ($c=0; $c < sizeof($sub_sentence); $c++) { if (isset($new_position[$sub_sentence['l_value']])) $sub_sentence['l_value'] = $new_position[$sub_sentence['l_value']]; else $sub_sentence['l_value'] = INVALID_POSITION; } return $sub_sentence; }*/ function pick_sub_sentence(&$sentence,$positions) { //print_r($positions); foreach ($positions as $position) { if ($position != INVALID_POSITION) { $new_positions[] = $position; if (isset($sentence[$position]['reference'])) $new_positions[] = $sentence[$position]['reference']; } } $sub_sentence = $sentence; for ($c=0; $c < sizeof($sub_sentence); $c++) { if (in_array($c,$new_positions)) { if (!in_array($sub_sentence[$c]['l_value'],$new_positions)) $sub_sentence[$c]['l_value'] = INVALID_POSITION; } else set_l_value_drop($sub_sentence[$c]); } return $sub_sentence; } function is_likely_prepositon_associated_with_predicate($raw_word) { if ($raw_word==WORD_OF) return false; else return true; } function reset_sentence_for_reprocessing(&$sentence) { for ($c=0; $c < sizeof($sentence); $c++) if (isset_primary_sentence_position($sentence,$c)) { $new_sentence[$c]['word'] = $sentence[$c]['word']; $new_sentence[$c]['raw_word'] = $sentence[$c]['raw_word']; if (is_preposition($sentence[$c]['word'])) { if (isset($sentence[$c]['former_l_value'])) //$new_sentence[$c]['pre_decided_l_value'] = $sentence[$c]['former_l_value']; $new_sentence[$c]['l_value'] = $sentence[$c]['former_l_value']; else if (isset($sentence[$c]['l_value'])) //$new_sentence[$c]['pre_decided_l_value'] = $sentence[$c]['l_value']; $new_sentence[$c]['l_value'] = $sentence[$c]['l_value']; } //if (isset($sentence[$c]['anchor_verb'])) // $new_sentence[$c]['anchor_verb'] = $sentence[$c]['anchor_verb']; $save_labels = array('verb','stop_marker','number_of_objects','decision'); foreach ($save_labels as $label) if (isset($sentence[$c][$label])) $new_sentence[$c][$label] = $sentence[$c][$label]; /* if (isset($sentence[$c]['stop_marker'])) $new_sentence[$c]['stop_marker'] = $sentence[$c]['stop_marker']; if (isset($sentence[$c]['number_of_objects'])) $new_sentence[$c]['number_of_objects'] = $sentence[$c]['number_of_objects']; */ } $sentence = $new_sentence; //deby("
Nach reset sentence for reprocessing: " . print_sentence_detailed($sentence)); } function output_make_selection() { output("
Choose what you are meaning:
"); } function query_number_of_objects_statistics_of_verb($word_id) { $sql = "SELECT * FROM statistics_number_of_objects WHERE word_id=$word_id"; $result = mysql_query_2($sql); if ($row = mysql_fetch_array($result)) return array($row['object0'],$row['object1'],$row['object2']); else return array(0,0,0); } function sql_query_number($sql) { $result = mysql_query_2($sql); if ($row = mysql_fetch_array($result)) return $row['number']; else return 0; } function query_statistics_edges_with_preposition(&$sentence,$left_value,$preposition,$right_value) { deby("
Query statistics edges with prepositions: left=$left_value, prepos=$preposition, right=$right_value"); $sql = "SELECT * FROM statistics_edges_with_preposition WHERE" . " word_id_0=" . get_selected_word_id_including_number($sentence,$right_value) . " AND word_id_1=" . get_selected_word_id_including_number($sentence,$left_value) . " AND preposition='" . chr(get_preposition_index($sentence,$preposition)) . "'"; return sql_query_number($sql); } function query_statistics_edges_allowing_preposition(&$sentence,$left_value,$l_type,$right_value) { if ($left_value == INVALID_POSITION || $right_value == INVALID_POSITION) return 0; if (is_preposition_selected($sentence,$left_value)) return query_statistics_edges_with_preposition($sentence,$sentence[$left_value]['l_value'],$left_value,$right_value); else return query_statistics_edges($sentence,$left_value,$l_type,$right_value); } function query_statistics_edges(&$sentence,$left_value,$l_type,$right_value) { deby("
Query statistics edges: left=$left_value, type=$l_type, right=$right_value"); if ($left_value == INVALID_POSITION || $right_value == INVALID_POSITION) return 0; $sql = "SELECT * FROM statistics_edges WHERE" . " word_id_0=" . get_selected_word_id_including_number($sentence,$right_value) . " AND word_id_1=" . get_selected_word_id_including_number($sentence,$left_value) . " AND l_type='" . $l_type . "'"; return sql_query_number($sql); } function statistically_query_sentence(&$sentence) { $number = 0; for ($position=0; $position < sizeof($sentence); $position++) { if (($l_value = $sentence[$position]['l_value']) != INVALID_POSITION) $number += query_statistics_edges($sentence,$l_value,$sentence[$position]['l_type'],$position); } return $number; } function refresh_statistics(&$sentence) { refresh_number_of_objects_statistics_of_verb($sentence); refresh_statistics_edges($sentence); } function refresh_number_of_objects_statistics_of_verb(&$sentence) { for ($c=0; $c < sizeof($sentence); $c++) { if (isset_primary_sentence_position($sentence,$c) && is_verb_selected($sentence,$c) && !is_variable($sentence[$c]['word']) && $sentence[$c]['l_type'] != L_TYPE_DROP) { for ($d=0; $d < 3; $d++) $object[$d] = 0; $number_of_objects = get_number_of_objects($sentence,$c); $object[$number_of_objects] = 1; $word = get_selected_word($sentence[$c]['word']); $sql = "INSERT INTO statistics_number_of_objects (word_id,object0,object1,object2)" . " VALUES (" . $word['word_id'] . "," . $object[0] . "," . $object[1] . "," . $object[2] . ")" . " ON DUPLICATE KEY UPDATE object" . $number_of_objects . "=object" . $number_of_objects . "+1"; mysql_query_2($sql); } } } function refresh_statistics_edges(&$sentence) { for ($c=0; $c < sizeof($sentence); $c++) { if ($sentence[$c]['l_type'] != L_TYPE_DROP) { $position = get_referred_position($sentence,$c); $l_value = $sentence[$c]['l_value']; if ($l_value != INVALID_POSITION) { $word_id_0 = get_selected_word_id_including_number($sentence,$position); $word_id_1 = get_selected_word_id_including_number($sentence,$l_value); if ($word_id_0 != INVALID_ID && $word_id_1 != INVALID_ID) { if (isset($sentence[$c]['preposition'])) $sql = "INSERT INTO statistics_edges_with_preposition (word_id_0,word_id_1,preposition,number)" . " VALUES (" . $word_id_0 . "," . $word_id_1 . ",'" . chr($sentence[$c]['preposition']) . "',1)"; else $sql = "INSERT INTO statistics_edges (word_id_0,word_id_1,l_type,number)" . " VALUES (" . $word_id_0 . "," . $word_id_1 . ",'" . $sentence[$c]['l_type'] . "',1)"; $sql .= " ON DUPLICATE KEY UPDATE number=number+1"; mysql_query_2($sql); } } } } } function get_number_of_objects(&$sentence,$position) { if (get_child($sentence,$position,M_TYPE) != INVALID_POSITION) return 2; if (get_child($sentence,$position,N_TYPE) != INVALID_POSITION) return 1; return 0; } /* function get_graph_of_sentence(&$sentence) { for ($c=0; $c < sizeof(sentence); $c++) { $graph = array() } }*/ function get_selected_word_id(&$sentence,$position) { // for ($position=0; $position < sizeof(sentence); $position++) // { $word = get_selected_word($sentence[$position]['word']); return $word['word_id']; } function get_selected_word_id_including_number(&$sentence,$position) { // for ($position=0; $position < sizeof(sentence); $position++) // { if (is_number($sentence[$position]['word'])) return 0; if (is_variable($sentence[$position]['word'])) return INVALID_ID; $word = get_selected_word($sentence[$position]['word']); return $word['word_id']; } /* function get_referred_cluster_word_id(&$sentence,$position) { return $sentence[get_referred_position($sentence,$position)]['sentence_id']; }*/ /* function get_information_for_database(&$sentence,$position) { $word_id = get_referred_word_id($sentence,$position); $cluster_word_id = get_referred_cluster_word_id($sentence,$position); $modus = get_referred_position($sentence,$position)]['modus']; $level = $sentence[get_referred_position($sentence,$position)]['level']; return array($word_id,$cluster_word_id,$modus,$level); }*/ function load_word_information_for_database(&$sentence,$position) { $referred_position = get_referred_position($sentence,$position); $sentence[$position]['word_id'] = get_array_value(get_selected_word($sentence[$referred_position]['word']),'word_id'); $sentence[$position]['cluster_word_id'] = $sentence[$referred_position]['sentence_id']; $sentence[$position]['modus'] = get_modus($sentence,$referred_position); $sentence[$position]['level'] = get_level($sentence,$referred_position); } function get_modus(&$sentence,$position) { if (isset($sentence[$position]['modus'])) return $sentence[$position]['modus']; else return 0; } function get_level(&$sentence,$position) { if (isset($sentence[$position]['level'])) return $sentence[$position]['level']; else return 0; } function get_preposition(&$sentence,$position,$referring_position) { if (isset($sentence[$referring_position]['preposition'])) return $sentence[$referring_position]['preposition']; /* if ($referring_position == $position) if (isset($sentence[$position]['preposition'])) return $sentence[$position]['preposition']; // else */ return 0; } /* function get_cluster_id(&$sentence,$position,$sub_position) { if (isset($sentence[$position]['cluster_id'])) return; return $sentence[$position]['sentence_id']; }*/ function get_highest_level(&$sentence) { $highest_level = 1000000; for ($c=0; $c < sizeof($sentence); $c++) { if ($sentence[$c]['l_type'] != L_TYPE_DROP) { if (isset($sentence[$c]['level'])) if ($sentence[$c]['level'] < $highest_level) { $highest_level = $sentence[$c]['level']; $highest_level_position = $c; } } } if (!isset($highest_level_position)) return array(0,INVALID_POSITION,INVALID_POSITION,0); for ($c=0; $c < sizeof($sentence); $c++) { if ($sentence[$c]['l_type'] != L_TYPE_DROP && $sentence[$c]['l_value'] != INVALID_POSITION) { $from = get_referred_position($sentence,$c); $to = $sentence[$c]['l_value']; if ($from == $highest_level_position) { $highest_level_index = $c; $highest_level_leftright = "0"; break; } if ($to == $highest_level_position) { $highest_level_index = $c; $highest_level_leftright = "1"; break; } } } return array($highest_level,$highest_level_position,$highest_level_index,$highest_level_leftright); } function query_one_word_sentence(&$sentence,$consider_modus,$search_options) //$consider_level,$unbound_level_start) { for ($c=0; $c < sizeof($sentence); $c++) { if ($sentence[$c]['l_type'] != L_TYPE_DROP) { $sql = "SELECT * FROM sentences WHERE "; for ($x=0; $x < 2; $x++) { $sql .= "(word_id_$x=" . get_selected_word_id($sentence,$c) . " AND "; if (isset($sentence[$c]['modus']) && $consider_modus) $sql .= "modus_$x=" . get_modus($sentence,$c) . " AND "; if (isset($sentence[$c]['level']) && !isset($search_options['ignore_level'])) $sql .= "level_$x=" . get_level($sentence,$c) . " AND "; $sql = substr($sql,0,-5); $sql .= ") OR "; } $sql = substr($sql,0,-4); return mysql_query_2($sql); } } } /* function analyse_and_plus_header(&$sentence,$position,$error,$first_l_value,$l_value,$skim_mode=false) { $anchor_and = INVALID_POSITION; if (!$error) { if ($first_l_value == INVALID_POSITION) $first_l_value = $l_value; //if ($error) // break; $anchor_and = $position; deby("bin bei object analyse und gehe jetzt auf and zu mit anchor_of_object = $l_value"); list($error,$position) = analyse_and($sentence,$position,$l_value,$skim_mode); } return array($error,$position,$anchor_and,$first_l_value); // list($error_and,$position,$right_value,$last_and) = // analyse_and_link_and($sentence,$position,$skim_mode,$anchor_of_object,$right_value,$last_and,$anchor_of_object); } */ function analyse_and(&$sentence,$position,$l_value,$skim_mode=false) { deby("
So, starte and:**: position=$position, l_value=$l_value, skim_mode=$skim_mode"); //if (is_conjunction($sentence[$position]['word'],true) && $sentence[$position]['raw_word'] == WORD_AND) if (isset_primary_sentence_position($sentence,$position) && is_and($sentence[$position]['word'],true)) { $sentence[$position]['l_type'] = L_TYPE; //deby("mhm and"); load_l_value_with_decision($sentence,$position); load_l_value_options($sentence,$position,$l_value); //,$predicate_of_object,$allow_refering_outside_of_sentence); if (($number_l_values = sizeof($sentence[$position]['l_value'])) > 1) { $sentence_2 = $sentence; // //list ($error_noun,$anchor_noun,$new_position,$gerund) = skim_noun($sentence,$position+1,0 /*$level*/,false /*$expect_noun*/); //analyse_noun($sentence_2,$position+1,false,true); /* list ($error_noun,$anchor_noun,$new_position,$gerund) = analyse_noun($sentence_2,$position+1,0,false,true,$position,M_TYPE); */ // try // { list($error_assertion,$pos,$anchor_verb,$gerund,$anchor_noun) = analyse_assertion($sentence_2,$position+1,0,false,true,INVALID_POSITION, false,true,INVALID_POSITION,true,INVALID_POSITION,false,true); //analyse_assertion(&$sentence,$position=0,$level=0,$expect_noun=false,$skim_mode=false,$anchor_subject=INVALID_POSITION,$no_subject_mode=false /* no_subject_mode */ // ,$change_passive_to_active=false,$question_verb=INVALID_POSITION,$allow_overwrite_subject=false, // $anchor_verb_of_expecting_noun=INVALID_POSITION,$relative=false,$phrase_mode=false,$l_value=INVALID_POSITION) // list($error_assertion,$pos,$anchor_verb,$gerund,$anchor_subject) // = skim_assertion($sentence,$position+1,0 /*$level+1*/,false /*$expect_noun*/,INVALID_POSITION,false,false, // INVALID_POSITION,true); //isset($sentence[$l_value]['relative'])); /* } catch (sentence_exception $exception) { $error_assertion = true; $anchor_verb = INVALID_POSITION; }*/ /* if ($anchor_noun == INVALID_POSITION) $error_noun = true; else $error_noun = false; */ for ($c=0; $c < $number_l_values; $c++) { //$test_l_value = $sentence[$position]['l_value'][$c]; if (test_and_option($sentence,$position,$c,$anchor_noun,$anchor_verb)) //,$anchor_subject)) $l_values[] = $sentence[$position]['l_value'][$c]; //$test_l_value; } //if (isset($l_values)) $sentence[$position]['l_value'] = $l_values; //else // $sentence[$position]['l_value'] = array(INVALID_POSITION); lift_single_l_value($sentence,$position); } deby("
so, and ist ausgefiltert." . $sentence[$position]['l_value']); if (sizeof($sentence[$position]['l_value']) > 1) { //if ($error_noun) // $anchor_noun = $anchor_verb; //else // $right_value_of_and = $anchor_noun; if (!isset($sentence[$position]['no_machine_decision']) && (($decided_position = try_to_decide_and($sentence_2,$position,$anchor_noun,$anchor_verb)) != INVALID_POSITION)) select_decided_l_value($sentence,$position,$decided_position); else { if ($skim_mode) { $sentence[$position]['l_value'] = $sentence[$position]['l_value'][0]; //$sentence[$position]['l_type'] = L_TYPE; } else { unset($sentence[$position]['no_machine_decision']); output_make_selection(); output(print_sentence_alternatives($sentence,true,L_TYPE,$anchor_noun,$anchor_verb)); throw new sentence_exception('decision',$position,$position); } } } else deby( "
HEY, AND POS gesetzt bei $position"); deby(" und zwar l_value = $l_value und entschiedene position = ". $sentence[$position]['l_value']); if ($sentence[$position]['l_value'] == $l_value) return array(false,$position+1); } return array('empty',$position); } function set_l_value(&$sentence,$position,$l_value,$l_type=L_TYPE) { $sentence[$position]['l_value'] = $l_value; $sentence[$position]['l_type'] = $l_type; } /* function link_and(&$sentence,$left_value,$and,$right_value) { deby("
link and: $left_value,$and,$right_value"); // set_l_value($sentence,$left_value,$and); add_reference_word_to_sentence($sentence,$left_value,$and,L_TYPE); set_l_value($sentence,$and,$right_value); // $sentence[$left_value]['l_value'] = $and; // $sentence[$left_value]['l_type'] = L_TYPE; // add_reference_word_to_sentence($sentence,$right_value,$and,N_TYPE); // set_l_value_end($sentence[$and]); }*/ function remove_and(&$sentence) { // return; //deby("....." . print_sentence_detailed($sentence)); die(); // $remaining_and = true; // while ($remaining_and) { // $remaining_and = false; for ($position=0; $position < sizeof($sentence); $position++) { if ($sentence[$position]['l_type'] != L_TYPE_DROP && is_and($sentence[$position]['word'])) { $right_value = get_child($sentence,$position,L_TYPE); $left_value = $sentence[$position]['l_value']; // deby("
left= $left_value - $right_value __"); die(); //if (!is_and($sentence[$right_value]['word'])) { copy_l_value_and_type($sentence,$left_value,$right_value); copy_preposition($sentence,$left_value,$right_value); //$sentence[$left_value]['l_value'] = $sentence[$right_value]['l_value']; //$sentence[$left_value]['l_type'] = $sentence[$right_value]['l_type']; set_l_value_drop($sentence[$position]); } // else // $remaining_and = true; } } /* if (!$remaining_and) break;*/ } //deby(print_sentence_detailed($sentence)); die(); } function load_l_value_with_decision(&$sentence,$position) { if (isset($sentence[$position]['decision'])) // && !isset($sentence[$position]['no_machine_decision'])) { deby ("
yes habe schon decision an pos $position"); $sentence[$position]['l_value'] = $sentence[$position]['decision']; } if (isset($sentence[$position]['no_machine_decision'])) unset($sentence[$position]['l_value']); } function load_l_value_options(&$sentence,$position,$l_value,$predicate_of_object=INVALID_POSITION,$allow_refering_outside_of_sentence=true) { if (!isset($sentence[$position]['l_value'])) { /*if ($m_value == L_VALUE_END) $sentence[$position]['l_value'] = $last_l_value; else { */ $current_l_value = $l_value /*$last_l_value*/; while ($current_l_value != INVALID_POSITION) { deby( " vorschlagsposition = $current_l_value"); deby(print_sentence_detailed($sentence)); $sentence[$position]['l_value'][] = $current_l_value; if (!$allow_refering_outside_of_sentence) { deby( "

LEIDER

"); if ($current_l_value == $predicate_of_object) {deby("
So ich breche ab!"); break;} } //if ($current_l_value==6) {echo print_sentence_detailed($sentence); die();} $current_l_value = get_parent_word_allowing_prepositional_children($sentence,$current_l_value); /* //if ($current_l_value == INVALID_POSITION) // break; if ($current_l_value == $anchor_of_object) //$position_start) break; echo "__"; echo $current_l_value = $sentence[$sentence[$current_l_value]['l_value']]['l_value']; */ } /* if ($predicate_of_object != L_VALUE_END) $sentence[$position]['l_value'][] = $predicate_of_object; */ //test_probability($position,$stop_m_value); /*$sentence[$position]['l_value'][0] = $last_l_value; $sentence[$position]['l_value'][1] = $m_value; */ //$position++; //$error = 'decision'; //break; //} //deby("
vor dem ominösen: " . print_sentence_detailed($sentence)); if (!isset($sentence[$position]['l_value'])) $sentence[$position]['l_value'] = array(INVALID_POSITION); lift_single_l_value($sentence,$position); } } function select_decided_l_value(&$sentence,$position,$decided_position) { //if (isset($sentence[$position]['pre_decided_l_value'])) // $sentence[$position]['l_value'] = $sentence[$position]['pre_decided_l_value']; //else //if (($decided_position = try_to_decide_l_value($sentence,$local_anchor_noun)) != INVALID_POSITION) //{ deby( "
entscheidung computer gefällt "); $sentence[$position]['l_value'] = $sentence[$position]['l_value'][$decided_position]; $sentence[$position]['l_type'] = L_TYPE; $sentence[$position]['decision'] = $sentence[$position]['l_value']; //"machine"; //$error = false; //if (check_for_end_of_object($sentence,$position_start,$predicate_of_object,$decision_position)) /* if ($sentence[$position]['l_value'] == $predicate_of_object || $sentence[$position]['l_value'] < $position_start) { //echo " decided pos = "; //echo // $position = $decision_position; break; } */ //echo print_sentence_detailed($sentence); //} } /* function analyse_and_link_and(&$sentence,$position,$skim_mode,$valid_anchor,$left_value,$last_and,$right_value) { //deby("
Analyse sentence zwischen and fertig."); // if (!$error) { //deby("bin an position $position mit $error"); if ($last_and != INVALID_POSITION) link_and($sentence,$left_value,$last_and,$right_value); // unset($last_and); //deby("....." . print_sentence_detailed($sentence)); list($error,$position_after_and) = analyse_and($sentence,$position,$right_value,$skim_mode); //deby("....." . print_sentence_detailed($sentence)); if (!$error) { deby(" found and : " . $sentence[$position]['l_value'] . " : $valid_anchor "); if (isset($sentence[$position]['l_value'])) if ($sentence[$position]['l_value'] != $valid_anchor) //< $position_start) $error = 'empty'; //deby(" durchgekommen "); } } if ($error) return array($error,$position,$right_value,INVALID_POSITION); else return array($error,$position_after_and,$right_value,$position); } */ function link_forward_skimmed_noun(&$sentence,$position,$anchor_noun,$gerund) { if ($gerund) is_verb_continuous($sentence[$anchor_noun]['word'],true); else is_noun($sentence[$anchor_noun]['word'],true); //$sentence[$local_anchor_noun]['word'] = $sentence_2[$local_anchor_noun]['word']; //deby( "
Local Anchor noun for preposition = $local_anchor_noun"); $sentence[$anchor_noun]['l_value'] = $position; //deby( "
Setze Objekt $position auf l_value=$l_value, wobei new_pos = $new_position"); $sentence[$anchor_noun]['l_type'] = M_TYPE; } function lift_single_l_value(&$sentence,$position) { if (sizeof($sentence[$position]['l_value']) == 1) { //set_l_value($sentence,$position,$sentence[$position]['l_value'][0]); $sentence[$position]['l_value'] = $sentence[$position]['l_value'][0]; //$sentence[$position]['l_type'] = L_TYPE; //if ($sentence[$position]['l_value'] == $predicate_of_object) //if (check_for_end_of_object($sentence,$position_start,$predicate_of_object,$position)) // break; } } function test_and_option(&$sentence,$position,$index_l_value,$anchor_noun,$anchor_verb) //,$anchor_subject) { deby("
In test option $position,$index_l_value,$anchor_noun,$anchor_verb"); $l_value = $sentence[$position]['l_value'][$index_l_value]; deby(": l_value = $l_value"); if (is_noun_or_gerund_selected($sentence,$l_value)) { if ($anchor_noun == INVALID_POSITION) return false; if ($anchor_verb == INVALID_POSITION) return true; // if (is_free_subject($sentence,$l_value)) // return true; //print_r($sentence[$position]['l_value']); deby(print_sentence_detailed($sentence)); //die(); while ($l_value >= 0) { if (is_free_subject($sentence,$l_value)) return true; $l_value--; } //if (search_free_subject_before_position($sentence,$l_value) == INVALID_POSITION) // return false; //else // return true; /* for ($c=$index_l_value+1; $c < sizeof($sentence[$position]['l_value']); $c++) if (is_free_subject($sentence,$sentence[$position]['l_value'][$c])) break; //$error_link_verb = test_and_with_verb(); if ($c < sizeof($sentence[$position]['l_value'])) return true; else return false;*/ } else return ($anchor_verb != INVALID_POSITION); /* if (isset($sentence[$l_value]['relative'])) return true; else if ($anchor_subject == INVALID_POSITION) return true; else return false; */ } function is_free_subject(&$sentence,$position) { // if (!is_noun_or_gerund_selected($sentence,$l_value)) // return true; // if (isset($sentence[$position]['subject']) && get_child($sentence,$position,L_TYPE)==INVALID_POSITION) //return true; /* if ($sentence[$position]['l_value']==INVALID_POSITION && (($child = get_child($sentence,$position,L_TYPE))==INVALID_POSITION || isset($sentence[$child]['relative'])) ) */ if (isset($sentence[$position]['subject']) && $sentence[$position]['l_value']==INVALID_POSITION) return true; else return false; } /* function search_free_subject_before_position(&$sentence,$position) { while (--$position >= 0) if (is_free_subject($sentence_position)) }*/ /* function test_and_with_verb() { if (is_noun_or_gerund_selected($sentence,$position)) { return true; } else }*/ function get_index($needle,&$haystack) { for ($c=0; $c < sizeof($haystack); $c++) if ($haystack[$c]==$needle) return $c; return -1; } function copy_l_value_and_type(&$sentence,$from,$to) { $sentence[$to]['l_value'] = $sentence[$from]['l_value']; $sentence[$to]['l_type'] = $sentence[$from]['l_type']; } function copy_preposition(&$sentence,$from,$to) { if (isset($sentence[$from]['preposition'])) $sentence[$to]['preposition'] = $sentence[$from]['preposition']; } function get_anchor_of_noun_sequence(&$sentence,$position) { $level = 0; while ($sentence[$position]['l_type'] == NOUN_TYPE) { $position = $sentence[$position]['l_value']; $level++; } return array($position,$level); } /* function get_cluster_id(&$sentence,$position,$from_or_to); { return $sentence[$position]['sentence_id'] * 2 + $from_or_to; }*/ /* function cluster_id_to(&$sentence,$position); { return $sentence[$position]['sentence_id'] * 2 + 1; }*/ /* function get_cluster_id(&$sentence,$position,$referring_position) { if (isset($sentence[$position]['reference_for_cluster_id'])) $sentence[$position]['cluster_id'] = cluster_id_from($sentence,$position); else if (!isset($sentence[$position]['cluster_id'])) $sentence[$position]['cluster_id'] = cluster_id_from($sentence,$position); //$sentence[$position]['sentence_id'] * 2; } */ function analyse_there(&$sentence,$position) //,$l_value,$l_type) { if (isset_primary_sentence_position($sentence,$position) && $sentence[$position]['raw_word'] == WORD_THERE && is_particle($sentence[$position]['word'],true)) { set_l_value_end($sentence[$position]); return array(false,$position+1,$position); } else return array('empty',$position,$position); } function delete_sentence($input_id) { $sql = "DELETE FROM sentences WHERE input_id=$input_id"; mysql_query_2($sql); //die(); } /* function split_input_into_words($input) { for ($c=0; $c < sizeof($input); $c++) { list($word,$type) = read_word($input,$c); if ($word == "") break; $words[] = $word; $type[] = $type; } }*/ function read_white_space(&$input,$position) { while ($position < strlen($input)) { $char = substr($input,$position,1); if ($char==" " || $char=="\t" || $char=="\n") $position++; else break; } return $position; } function read_word(&$input,$position) { for ($c=$position; $c < strlen($input); $c++) { $char = substr($input,$c,1); if ($char==" " || $char=="\t" || $char=="\n" || $char==CHAR_QUOTION_MARK) break; if ($char==CHAR_COMMA || $char==CHAR_POINT) { if ($position == $c) $c++; break; } } return array($c,substr($input,$position,$c-$position)); } function read_string(&$input,$position) { if ($position >= strlen($input) || substr($input,$position,1) != CHAR_QUOTION_MARK) return array($position,""); for ($c=$position+1; $c < strlen($input); $c++) { $char = substr($input,$c,1); if ($input[$c] == CHAR_QUOTION_MARK) break; } return array($c+1,substr($input,$position+1,$c-$position-1)); } function is_raw_word_variable($word) { return (substr($word,0,1) == CHAR_STRING); } function rename_variable_for_sql($word) { return "v_" . substr($word,1); } function read_word_or_string_or_number(&$input,$position) { list($position,$word) = read_string($input,$position); if ($word != "") return array($position,$word,true,false,false,0); list($position,$word) = read_word($input,$position); if ($word != "") return array($position,$word,false,true,false,0); } /* function read_word(&$input,$position) { $start = -1; $quotion_mark_mode = false; for ($c=$position; $c < sizeof($input); $c++) { $char = $input[$c]; if (!$quotion_mark_mode && ($char==" " || $char=="\t" || $char=="\n")) { if ($start >= 0) break; } else { if ($char=="\"") if ($start >= 0) { $end=$c++; break; } else { $quotion_mark_mode = true; $start = $c+1; } else $word_mode = true; if ($quotion_) } } */ function add_html_reference_to_url(&$text) { } function enter_word_if_not_exists($word,$type,$stem_id=0,$number=0) { $result = query_word($word); if (!mysql_fetch_array($result)) insert_new_word_in_word_table($word,$type,$stem_id,$number); } /* function encode_number_to_word_id($number) { if ($number < 0) { $sign = true; $number = -$number; else $sign = false; $number = (int) (($number)*pow(2,16)); }*/ function number_of_childs(&$sentence,$position) { $counter = 0; for ($c=0; $c < sizeof($sentence); $c++) if (isset($sentence[$c]['l_value']) && $sentence[$c]['l_value'] == $position) $counter++; return $counter; } function number_of_edges(&$sentence,$position) { $counter = number_of_childs($sentence,$position); if ($sentence[$position]['l_value'] != INVALID_POSITION) return $counter+1; else return $counter; } function analyse_variable(&$sentence,$position,$l_value=INVALID_POSITION,$l_type=L_TYPE) { if (isset_primary_sentence_position($sentence,$position) && is_variable($sentence[$position]['word'])) { $sentence[$position]['l_value'] = $l_value; $sentence[$position]['l_type'] = $l_type; return array(false,$position+1,$position); } else return array('empty',$position,$position); } function analyse_pullstop(&$sentence,$position) { if (isset_primary_sentence_position($sentence,$position) && is_pullstop($sentence[$position]['word'],true)) { set_l_value_drop($sentence[$position]); return array(false,$position+1); } else return array('empty',$position); } function get_right_and_l_value_of_and_option(&$sentence,$l_value,$anchor_noun,$anchor_verb) { if (is_noun_or_gerund_selected($sentence,$l_value)) { $right_value = $anchor_noun; $l_value = $sentence[$l_value]['l_value']; //$l_type = $sentence[$l_value]['l_type']; if ($l_value==INVALID_POSITION) { $right_value = $anchor_verb; //$l_type = L_TYPE_END; } } else { $right_value = $anchor_verb; $l_value = get_referred_position($sentence,get_child($sentence,$l_value,S_TYPE)); /* if ($anchor_noun != INVALID_POSITION) $l_type = N_TYPE; //unsauber?: was wenn es M_TYPE wird else $l_type = S_TYPE; */ } //$l_value = get_referred_position($sentence,$sentence[$l_value]['l_value']); return array($l_value,$right_value); } function try_to_decide_and(&$sentence,$position,$anchor_noun,$anchor_verb) { for ($c=0; $c < sizeof($sentence[$position]['l_value']); $c++) { $l_value_of_and = $sentence[$position]['l_value'][$c]; list($l_value,$right_value) = get_right_and_l_value_of_and_option($sentence,$l_value_of_and,$anchor_noun,$anchor_verb); /* if ($anchor_verb != INVALID_POSITION) is_verb($sentence[$anchor_verb]['word'],true); if ($anchor_noun != INVALID_POSITION) is_verb($sentence[$anchor_noun]['word'],true); */ deby("
bin in try decide and and bekomme: l_value=$l_value, right_value=$right_value"); if ($right_value == $anchor_verb) { if ($anchor_noun != INVALID_POSITION) { $number_of_occurences[$c] = (query_statistics_edges($sentence,$anchor_verb,N_TYPE,$l_value) + query_statistics_edges($sentence,$anchor_verb,S_TYPE,$anchor_noun)); if ($l_value != INVALID_POSITION) $number_of_occurences[$c] /= 2; } else $number_of_occurences[$c] = query_statistics_edges($sentence,$anchor_verb,S_TYPE,$l_value); } else $number_of_occurences[$c] = query_statistics_edges_allowing_preposition($sentence,$l_value,$sentence[$l_value_of_and]['l_type'],$right_value); deby( " occurences: " . $number_of_occurences[$c]); } return try_to_decide_by_probability($number_of_occurences); } function print_decisions(&$sentence,$error=false) { if (!$error) { $decisions_text = print_sentence_highlight_decided($sentence); if ($decisions_text != "") { $text = "
Click highlighted parts for correcting wrong connections:
"; //$primary_sentence = get_primary_sentence($sentence); $text .= "

" . $decisions_text . "

"; output($text); } } } function fusion_double_edges(&$sentence) { $sizeof_sentence = sizeof($sentence); for ($c1=0; $c1 < $sizeof_sentence; $c1++) { if ($sentence[$c1]['l_type'] != L_TYPE_DROP && $sentence[$c1]['l_value'] != INVALID_POSITION) { for ($c2=0; $c2 < $sizeof_sentence; $c2++) { if ($sentence[$c2]['l_type'] != L_TYPE_DROP && $sentence[$c2]['l_value'] != INVALID_POSITION) { $vertex1[0] = get_referred_position($sentence,$c1); $vertex1[1] = $sentence[$c1]['l_value']; $vertex2[0] = get_referred_position($sentence,$c2); $vertex2[1] = $sentence[$c2]['l_value']; $type1 = $sentence[$c1]['l_type']; $type2 = $sentence[$c2]['l_type']; if ($vertex1[1] == $vertex2[0]) { if (isset($sentence[$vertex2[0]]['preposition']) || is_verb_selected($sentence,$vertex2[1])) { $new_edge = add_reference_word_to_sentence($sentence,$vertex1[0],$vertex2[1],$type2); copy_preposition($sentence,$vertex2[0],$new_edge); } else { $new_edge = add_reference_word_to_sentence($sentence,$vertex1[0],$vertex2[1],$type1); copy_preposition($sentence,$c1,$new_edge); } } if (($vertex1[1] == $vertex2[1]) && ($vertex1[0] != $vertex2[0]) && ($type1 == S_TYPE || $type1 == N_TYPE)) { if (is_verb_selected($sentence,$vertex2[0])) $new_edge = add_reference_word_to_sentence($sentence,$vertex1[0],$vertex2[0],S_TYPE); else if (isset($sentence[$vertex2[0]]['preposition'])) { $new_edge = add_reference_word_to_sentence($sentence,$vertex2[0],$vertex1[0],$type2); copy_preposition($sentence,$vertex2[0],$new_edge); } } } } } } } function check_url($url) { if (substr($url,0,5)=="http:") return $url; else return "http://$url"; } ?>