private function parseAsk ( $text, WikiObjectModelCollection $parentObj ) { if ( !defined( 'SMW_VERSION' ) ) return null; if ( trim( strtolower( $parentObj->getFunctionKey() ) ) != 'ask' ) return null; if ( count ( $parentObj->getObjects() ) == 0 ) { return array( 'len' => 0, 'obj' => new WOMQuerystringModel() ); } if ( defined( 'SMW_AGGREGATION_VERSION' ) ) { $r = preg_match( '/^(\s*\?([^>=|}]+)(?:\>([^=|}]*))?(?:=([^|}]*))?)(\||\}|$)/', $text, $m ); if ( !$r ) return null; return array( 'len' => strlen( $m[5] == '|' ? $m[0] : $m[1] ), 'obj' => new WOMQueryPrintoutModel( trim( $m[2] ), trim( $m[4] ), trim( $m[3] ) ) ); } else { $r = preg_match( '/^(\s*\?([^=|}]+)(?:=([^|}]*))?)(\||\}|$)/', $text, $m ); if ( !$r ) return null; return array( 'len' => strlen( $m[4] == '|' ? $m[0] : $m[1] ), 'obj' => new WOMQueryPrintoutModel( trim( $m[2] ), trim( $m[3] ) ) ); } }
private static function removeSubWOMIds( WikiObjectModelCollection $parent ) { foreach ( $parent->getObjects() as $wobj ) { $wobj->setObjectID( '' ); if ( $wobj instanceof WikiObjectModelCollection ) { self::removeSubWOMIds( $wobj ); } } }
private static function parseSentences( WikiObjectModelCollection $wom ) { global $wgOMSentenceObjectTypes; $in_sentence = false; $new_objs = array(); $sentenceObj = null; foreach ( $wom->getObjects() as $id => $obj ) { if ( in_array( $obj->getTypeID(), $wgOMSentenceObjectTypes ) ) { if ( !$in_sentence ) { $sentenceObj = new WOMSentenceModel(); $new_objs[] = $sentenceObj; $in_sentence = true; } $sentenceObj->insertObject( $obj ); // parse sentence break if ( $obj->getTypeID() == WOM_TYPE_TEXT ) { $text = $obj->getWikiText(); $offset = 0; $len = strlen( $text ); // FIXME: sentence algorithm here, for now, just think of // \n // [.?!]((['"]|'{2,6})?)<space> // shall think of other language, e.g., Chinese $r = preg_match_all( '/(\n[^\n])|(([\.!?](([\'"]|\'{2,6})?))([ \t]))/', $text, $ms, PREG_SET_ORDER | PREG_OFFSET_CAPTURE ); if ( $r ) { foreach ( $ms as $m ) { if ( $m[1][1] >= 0 ) { $end = $m[0][1] + 1; } else { $end = $m[0][1] + strlen( $m[0][0] ); } $obj->setText( substr( $text, $offset, $end - $offset ) ); $offset = $end; if ( $end == $len ) break; $sentenceObj = new WOMSentenceModel(); $new_objs[] = $sentenceObj; $obj = new WOMTextModel( substr( $text, $end ) ); $sentenceObj->insertObject( $obj ); } } } } else { $in_sentence = false; $sentenceObj = null; if ( $obj->getTypeID() == WOM_TYPE_HTMLTAG ) { // special case, html tag } elseif ( $obj instanceof WikiObjectModelCollection ) { self::parseSentences( $obj ); } $new_objs[] = $obj; } } $wom->reset(); foreach ( $new_objs as $obj ) { $wom->insertObject( $obj ); } }