jenkins-bot has submitted this change and it was merged.
Change subject: Cleanup Code
......................................................................
Cleanup Code
Change-Id: I1ac63c91955b70b72368303a12a7ef46aae20b03
---
M MathObject.php
M MathQueryObject.php
2 files changed, 124 insertions(+), 109 deletions(-)
Approvals:
Physikerwelt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MathObject.php b/MathObject.php
index 9519003..548c36b 100644
--- a/MathObject.php
+++ b/MathObject.php
@@ -309,6 +309,7 @@
*/
public static function extractMathTagsFromWikiText( $wikiText ) {
$wikiText = Sanitizer::removeHTMLcomments( $wikiText );
+ //TODO:Check if this is necessary?
$wikiText = preg_replace( '#<nowiki>(.*)</nowiki>#', '',
$wikiText );
$matches = array();
Parser::extractTagsAndParams( array( 'math' ), $wikiText,
$matches );
diff --git a/MathQueryObject.php b/MathQueryObject.php
index 6eca335..7aeae76 100644
--- a/MathQueryObject.php
+++ b/MathQueryObject.php
@@ -8,53 +8,56 @@
private $texquery = false;
private $cquery = false;
private $pquery = false;
- /** @var XQueryGenerator current instance of xQueryGenerator */
+ /** @var XQueryGenerator current instance of xQueryGenerator */
private $xQuery = false;
private $xQueryDialect = false;
-/* ToDo: Update to new format
-<code>
- latexmlc --whatsin=fragment --path=$(LLIB) \
---preamble=$(LLIB)/pre.tex --postamble=$(LLIB)/post.tex \
---format=xml --cmml --pmml --preload=[ids]latexml.sty \
---stylesheet=$(LLIB)/ntcir11-topic.xsl \
---destination=$@ --log=$(basename $<).ltxlog $<
-</code> see http://kwarc.info/kohlhase/event/NTCIR11/
-*/
+ /* ToDo: Update to new format
+ <code>
+ latexmlc --whatsin=fragment --path=$(LLIB) \
+ --preamble=$(LLIB)/pre.tex --postamble=$(LLIB)/post.tex \
+ --format=xml --cmml --pmml --preload=[ids]latexml.sty \
+ --stylesheet=$(LLIB)/ntcir11-topic.xsl \
+ --destination=$@ --log=$(basename $<).ltxlog $<
+ </code> see http://kwarc.info/kohlhase/event/NTCIR11/
+ */
- private $pmmlSettings = array('format' => 'xml',
- 'whatsin' => 'math',
- 'whatsout' => 'math',
- 'pmml',
- 'nodefaultresources',
- 'preload' => array(
- 'LaTeX.pool',
- 'article.cls',
- 'amsmath.sty',
- 'amsthm.sty',
- 'amstext.sty',
- 'amssymb.sty',
- 'eucal.sty',
- '[dvipsnames]xcolor.sty',
- 'url.sty',
- 'hyperref.sty',
- 'mws.sty',
-// '[ids]latexml.sty',
- 'texvc'),
+ private $pmmlSettings = array(
+ 'format' => 'xml',
+ 'whatsin' => 'math',
+ 'whatsout' => 'math',
+ 'pmml',
+ 'nodefaultresources',
+ 'preload' => array(
+ 'LaTeX.pool',
+ 'article.cls',
+ 'amsmath.sty',
+ 'amsthm.sty',
+ 'amstext.sty',
+ 'amssymb.sty',
+ 'eucal.sty',
+ '[dvipsnames]xcolor.sty',
+ 'url.sty',
+ 'hyperref.sty',
+ 'mws.sty',
+ // '[ids]latexml.sty',
+ 'texvc'
+ ),
);
/**
* @param string $texquery the TeX-like search input
* @param string $xQueryDialect e.g. db2 or basex
*/
- public function __construct( $texquery='' , $xQueryDialect = 'db2' ) {
+ public function __construct( $texquery = '', $xQueryDialect = 'db2' ) {
$this->texquery = $texquery;
$this->xQueryDialect = $xQueryDialect;
}
+
/**
* Set the query id
* @param int $id
*/
- public function setQueryId($id){
+ public function setQueryId( $id ) {
$this->queryID = $id;
}
@@ -62,7 +65,8 @@
$texInput = htmlspecialchars( $this->getUserInputTex() );
$texInputComment = preg_replace( "/[\n\r]/", "\n%", $texInput );
$title = Title::newFromId( $this->getPageID() );
- $absUrl = $title->getFullURL( array( "oldid" =>
$title->getLatestRevID() ) ) .
+ $absUrl =
+ $title->getFullURL( array( "oldid" =>
$title->getLatestRevID() ) ) .
MathSearchHooks::generateMathAnchorString(
$title->getLatestRevID(), $this->getAnchorID() );
return <<<TeX
\begin{topic}{{$this->getPageTitle()}-{$this->getAnchorID()}}
@@ -82,22 +86,23 @@
}
/**
- *
+ *
* @param ResultWrapper $rpage
- * @param int $queryID
+ * @param bool|int $queryID
* @return \self
*/
- public static function newQueryFromEquationRow($rpage, $queryID =
false) {
- $instance = self::constructformpagerow($rpage);
- $instance->setQueryId($queryID);
+ public static function newQueryFromEquationRow( $rpage, $queryID =
false ) {
+ $instance = self::constructformpagerow( $rpage );
+ $instance->setQueryId( $queryID );
return $instance;
}
+
/**
* Returns the queryId. If not set a random query id will be generated.
* @return int
*/
- public function getQueryId(){
- if ($this->queryID === false ){
+ public function getQueryId() {
+ if ( $this->queryID === false ) {
$this->queryID = rand();
}
return $this->queryID;
@@ -108,8 +113,8 @@
* If not set a a query id will be generated.
* @return string
*/
- public function getTeXQuery(){
- if ($this->texquery == false ){
+ public function getTeXQuery() {
+ if ( $this->texquery == false ) {
$this->injectQvar();
}
return $this->texquery;
@@ -120,8 +125,8 @@
* If not set a random query id will be generated based on the TeXQuery.
* @return string
*/
- public function getCQuery(){
- if ($this->cquery === false ){
+ public function getCQuery() {
+ if ( $this->cquery === false ) {
$this->generateContentQueryString();
}
return $this->cquery;
@@ -132,8 +137,8 @@
* If not set a random query id will be generated based on the TeXQuery.
* @return string
*/
- public function getPQuery(){
- if ($this->pquery === false ){
+ public function getPQuery() {
+ if ( $this->pquery === false ) {
$this->generatePresentationQueryString();
}
return $this->pquery;
@@ -142,65 +147,67 @@
/**
* @return bool|string
*/
- public function serlializeToXML( ){
- $cx = simplexml_load_string($this->getCQuery());
- $px = simplexml_load_string($this->getPQuery());
- if ( $cx == false || $px == false ){
+ public function serlializeToXML() {
+ $cx = simplexml_load_string( $this->getCQuery() );
+ $px = simplexml_load_string( $this->getPQuery() );
+ if ( $cx == false || $px == false ) {
return false;
}
- $xCore = preg_replace("/\\n/","\n\t\t",
$cx->children('mws',TRUE)->children('m',TRUE)->asXML());
- $pmml = preg_replace(array( '#<mi (.*)
mathcolor="red">(.*)</mi>#' , "/\\n/" ),
- array( '<mws:qvar
xmlns:mws="http://www.mathweb.org/mws/ns" name="$2"/>', "\n\t\t" ),
- $px->children()->asXML());
+ $xCore =
+ preg_replace( "/\\n/", "\n\t\t", $cx->children( 'mws',
TRUE )->children( 'm', TRUE )->asXML() );
+ $pmml =
+ preg_replace( array( '#<mi (.*)
mathcolor="red">(.*)</mi>#', "/\\n/" ),
+ array( '<mws:qvar
xmlns:mws="http://www.mathweb.org/mws/ns" name="$2"/>', "\n\t\t" ),
+ $px->children()->asXML() );
$out = '<topic xmlns="http://ntcir-math.nii.ac.jp/">';
- $out .= "\n\t<num>FSE-GC-". $this->getQueryId() ."</num>";
+ $out .= "\n\t<num>FSE-GC-" . $this->getQueryId() . "</num>";
$out .= "\n\t<type>Content-Query</type>";
- $out .= "\n\t<title>Query ".$this->getQueryId()."
(".$this->getPageTitle().")<title>";
+ $out .= "\n\t<title>Query " . $this->getQueryId() . " (" .
$this->getPageTitle() . ")<title>";
$out .= "\n\t<query>";
- $out.= "\n\t\t<TeXquery>{$this->getTeXQuery()}</TeXquery>";
- $out.= "\n\t\t<pquery>{$pmml}</pquery>";
- $out.= "\n\t\t<cquery><m:math>{$xCore}</m:math></cquery>";
+ $out .= "\n\t\t<TeXquery>{$this->getTeXQuery()}</TeXquery>";
+ $out .= "\n\t\t<pquery>{$pmml}</pquery>";
+ $out .= "\n\t\t<cquery><m:math>{$xCore}</m:math></cquery>";
$out .= "\n\t</query>";
- $out .= "\n\t<relevance>find result similar to "
- . "<a
href=\"http://demo.formulasearchengine.com/index.php?"
- .
"curid={$this->getPageID()}#math{$this->getAnchorID()}\">"
- . htmlspecialchars( $this->getUserInputTex())
."</a></relevance>";
- $out.="\n</topic>\n";
+ $out .= "\n\t<relevance>find result similar to " .
+ "<a
href=\"http://demo.formulasearchengine.com/index.php?" .
+
"curid={$this->getPageID()}#math{$this->getAnchorID()}\">" .
+ htmlspecialchars( $this->getUserInputTex() ) .
"</a></relevance>";
+ $out .= "\n</topic>\n";
return $out;
- }
+ }
public function injectQvar() {
$out = "";
$level = 0;
$qVarLevel = PHP_INT_MAX;
$qVarNo = 0;
- foreach (str_split($this->getTex()) as $currentchar) {
- switch ($currentchar) {
+ foreach ( str_split( $this->getTex() ) as $currentchar ) {
+ switch ( $currentchar ) {
case '{':
- $level++;
- if ($level >= self::MIN_DEPTH && $level
< $qVarLevel) {
- if ((mt_rand() /
mt_getrandmax()) < self::SELECTIVITY_QVAR * $level) {
+ $level ++;
+ if ( $level >= self::MIN_DEPTH &&
$level < $qVarLevel ) {
+ if ( ( mt_rand() /
mt_getrandmax() ) < self::SELECTIVITY_QVAR * $level ) {
$qVarLevel = $level;
- $out.="{?{x" .
$qVarNo++ . "}";
+ $out .= "{?{x" .
$qVarNo ++ . "}";
} else {
- $out .='{';
+ $out .= '{';
}
} else {
- if ($level < $qVarLevel) {
- $out.='{';
+ if ( $level < $qVarLevel ) {
+ $out .= '{';
}
}
break;
case '}':
- $level--;
- if ($level < $qVarLevel) {
+ $level --;
+ if ( $level < $qVarLevel ) {
$qVarLevel = PHP_INT_MAX;
- $out.="}";
+ $out .= "}";
}
break;
default:
- if ($level < $qVarLevel) {
- $out.=$currentchar;
+ if ( $level < $qVarLevel ) {
+ $out .= $currentchar;
}
}
}
@@ -208,7 +215,7 @@
return $out;
}
- public function getLaTeXMLCMMLSettings(){
+ public function getLaTeXMLCMMLSettings() {
global $wgMathDefaultLaTeXMLSetting;
$cSettings = $wgMathDefaultLaTeXMLSetting;
$cSettings['preload'][] = 'mws.sty';
@@ -216,31 +223,32 @@
return $cSettings;
}
- public function getLaTeXMLPMLSettings(){
+ public function getLaTeXMLPMLSettings() {
global $wgMathDefaultLaTeXMLSetting;
- $cSettings = array_diff($wgMathDefaultLaTeXMLSetting,
array('cmml'));
+ $cSettings = array_diff( $wgMathDefaultLaTeXMLSetting, array(
'cmml' ) );
$cSettings['preload'][] = 'mws.sty';
$cSettings['stylesheet'] = 'MWSquery.xsl';
return $cSettings;
}
- public function generateContentQueryString(){
- $renderer = new MathLaTeXML($this->getTexQuery());
- $renderer->setLaTeXMLSettings($this->getLaTeXMLCMMLSettings());
- $renderer->setAllowedRootElements(array('query'));
- if ( $renderer->render(true) ){
+
+ public function generateContentQueryString() {
+ $renderer = new MathLaTeXML( $this->getTexQuery() );
+ $renderer->setLaTeXMLSettings( $this->getLaTeXMLCMMLSettings()
);
+ $renderer->setAllowedRootElements( array( 'query' ) );
+ if ( $renderer->render( true ) ) {
$this->cquery = $renderer->getMathml();
return $this->cquery;
} else {
- wfDebugLog('math', 'error during geration of query
string'. $renderer->getLastError());
+ wfDebugLog( 'math', 'error during geration of query
string' . $renderer->getLastError() );
}
}
- public function generatePresentationQueryString(){
- $renderer = new MathLaTeXML($this->getTexQuery());
- $renderer->setXMLValidaton(false);
+ public function generatePresentationQueryString() {
+ $renderer = new MathLaTeXML( $this->getTexQuery() );
+ $renderer->setXMLValidaton( false );
//$renderer->setAllowedRootElments(array('query'));
- $renderer->setLaTeXMLSettings($this->pmmlSettings);
- if ($renderer->render(true) ) {
+ $renderer->setLaTeXMLSettings( $this->pmmlSettings );
+ if ( $renderer->render( true ) ) {
$this->pquery = $renderer->getMathml();
return $this->pquery;
} else {
@@ -250,16 +258,16 @@
}
/**
- *
- * @param String ("DB2"|"BaseX") $dialect the name of the
xQueryGenerator
+ *
+ * @param String ("DB2"|"BaseX") $dialect the name of the
xQueryGenerator
* @return XQueryGenerator
* @throws Exception
*/
- public function setXQueryDialect( $dialect = false ){
- if ($dialect === false){
+ public function setXQueryDialect( $dialect = false ) {
+ if ( $dialect === false ) {
$dialect = $this->xQueryDialect;
}
- switch ($dialect) {
+ switch ( $dialect ) {
case 'db2':
$this->xQuery = new XQueryGeneratorDB2(
$this->getCQuery() );
break;
@@ -267,15 +275,17 @@
$this->xQuery = new XQueryGeneratorBaseX(
$this->getCQuery() );
break;
default:
- throw new Exception($dialect . 'is not a valid
XQueryDialect');
+ throw new Exception( $dialect . 'is not a valid
XQueryDialect' );
}
return $this->xQuery;
}
- public function setXQueryGenerator($xQueryGenerator){
+
+ public function setXQueryGenerator( $xQueryGenerator ) {
$this->xQuery = $xQueryGenerator;
}
- public function getXQueryGenerator(){
- if ($this->xQuery === false){
+
+ public function getXQueryGenerator() {
+ if ( $this->xQuery === false ) {
$this->setXQueryDialect();
}
return $this->xQuery;
@@ -285,11 +295,11 @@
* @see XQueryGenerator::getXQuery()
* @return String
*/
- public function getXQuery(){
+ public function getXQuery() {
return $this->getXQueryGenerator()->getXQuery();
}
- /**
+ /**
* Posts the query to mwsd and evaluates the result data
* @return boolean
*/
@@ -297,7 +307,8 @@
global $wgMathSearchMWSUrl, $wgMathDebug;
$numProcess = 30000;
- $tmp = str_replace( "answsize=\"30\"",
"answsize=\"$numProcess\" totalreq=\"yes\"", $this->getCQuery() );
+ $tmp =
+ str_replace( "answsize=\"30\"",
"answsize=\"$numProcess\" totalreq=\"yes\"", $this->getCQuery() );
$mwsExpr = str_replace( "m:", "", $tmp );
wfDebugLog( 'mathsearch', 'MWS query:' . $mwsExpr );
$res = Http::post( $wgMathSearchMWSUrl, array( "postData" =>
$mwsExpr, "timeout" => 60 ) );
@@ -314,8 +325,9 @@
} else {
$details = "curl is not installed.";
}
- wfDebugLog( "MathSearch", "Nothing retreived from
$wgMathSearchMWSUrl. Check if mwsd is running. Error:" .
- var_export( $details, true ) );
+ wfDebugLog( "MathSearch",
+ "Nothing retreived from $wgMathSearchMWSUrl.
Check if mwsd is running. Error:" .
+ var_export( $details, true ) );
return false;
}
$xres = new SimpleXMLElement( $res );
@@ -323,10 +335,11 @@
$out = $this->getOutput();
$out->addWikiText( '<source lang="xml">' . $res .
'</source>' );
}
- $this->numMathResults = (int) $xres["total"];
+ $this->numMathResults = (int)$xres["total"];
wfDebugLog( "MathSearch", $this->numMathResults . " results
retreived from $wgMathSearchMWSUrl." );
- if ( $this->numMathResults == 0 )
+ if ( $this->numMathResults == 0 ) {
return true;
+ }
$this->relevantMathMap = array();
$this->mathResults = array();
$this->processMathResults( $xres );
@@ -337,7 +350,8 @@
$res = Http::post( $wgMathSearchMWSUrl, array(
"postData" => $query, "timeout" => 60 ) );
wfDebugLog( 'mathsearch', 'MWS query:' . $query
);
if ( $res == false ) {
- wfDebugLog( "MathSearch", "Nothing
retreived from $wgMathSearchMWSUrl. check if mwsd is running there" );
+ wfDebugLog( "MathSearch",
+ "Nothing retreived from
$wgMathSearchMWSUrl. check if mwsd is running there" );
return false;
}
$xres = new SimpleXMLElement( $res );
--
To view, visit https://gerrit.wikimedia.org/r/173776
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1ac63c91955b70b72368303a12a7ef46aae20b03
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
Gerrit-Reviewer: Physikerwelt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits