Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7407992
IntentParserTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
IntentParserTest.php
View Options
<?php
namespace
MediaWiki\Extension\Math\WikiTexVC\Intent
;
use
MediaWiki\Extension\Math\WikiTexVC\MMLmappings\Util\MMLTestUtil
;
use
MediaWiki\Extension\Math\WikiTexVC\TexVC
;
use
MediaWikiIntegrationTestCase
;
/**
* This is a testbench for the currently experimental intent annotation feature.
* The base files for intent tests and intent annotated are extracted from W3 examples in HTML
* To (re-)generate the json testfiles from HTML an external program in nodejs is used, this can
* be found in GitHub: ..... tbd .... add link
*
* The output of this test is finally used to create a speech comparison with the mentioned program.
*
* @covers \MediaWiki\Extension\Math\WikiTexVC\TexVC
*/
final
class
IntentParserTest
extends
MediaWikiIntegrationTestCase
{
/** @var string */
private
static
$FILENAMEINTENTTESTS
=
__DIR__
.
"/intent_mathml_testing_extracted.json"
;
/** @var string */
private
static
$FILENAMEINTENTANNOTATED
=
__DIR__
.
"/intent_mathml_testing_latex_annotated.json"
;
/** @var bool */
private
static
$APPLYFILTER
=
false
;
/** @var int */
private
static
$FILTERSTART
=
3
;
/** @var int */
private
static
$FILTERLENGTH
=
2
;
/** @var bool */
private
static
$GENERATEJSONFILE
=
false
;
/** @var string */
private
static
$GENERATEDJSONFILE
=
__DIR__
.
"/IntentParserTestLocal-Output.json"
;
/** @var int[] */
private
static
$SKIPPEDINDICES
=
[
67
];
public
static
function
setUpBeforeClass
():
void
{
self
::
writeToFile
(
"[
\n
"
,
"w"
);
}
public
static
function
tearDownAfterClass
():
void
{
self
::
writeToFile
(
"
\n
]"
,
"a"
);
}
public
static
function
writeToFile
(
$data
,
$mode
):
void
{
if
(
!
self
::
$GENERATEJSONFILE
)
{
return
;
}
$fp
=
fopen
(
self
::
$GENERATEDJSONFILE
,
$mode
);
fwrite
(
$fp
,
$data
);
fclose
(
$fp
);
}
public
static
function
writeToJSONFile
(
$jsonData
,
$addComma
=
false
):
void
{
if
(
!
self
::
$GENERATEJSONFILE
)
{
return
;
}
$jsonString
=
json_encode
(
$jsonData
,
JSON_PRETTY_PRINT
);
$fp
=
fopen
(
self
::
$GENERATEDJSONFILE
,
'a'
);
if
(
$addComma
)
{
$jsonString
=
$jsonString
.
","
;
}
fwrite
(
$fp
,
$jsonString
);
fclose
(
$fp
);
}
/**
* @dataProvider provideTestCases
*/
public
function
testTexVC
(
$title
,
$tc
)
{
$texVC
=
new
TexVC
();
if
(
$tc
->
skipped
==
true
||
in_array
(
$tc
->
ctr
,
self
::
$SKIPPEDINDICES
,
true
)
)
{
$this
->
addToAssertionCount
(
1
);
return
;
}
# Fetch result from TexVC(PHP)
$resultT
=
$texVC
->
check
(
$tc
->
latexi
,
[
'debug'
=>
false
,
'usemathrm'
=>
$tc
->
usemathrm
??
false
,
"useintent"
=>
true
,
"usemhchem"
=>
$tc
->
usemhchem
,
'oldtexvc'
=>
$tc
->
oldtexvc
??
false
]
);
if
(
!
isset
(
$resultT
[
"input"
]
)
)
{
if
(
$tc
->
shouldfail
)
{
$this
->
addToAssertionCount
(
1
);
return
;
}
}
$mathMLtexVC
=
MMLTestUtil
::
getMMLwrapped
(
$resultT
[
"input"
]
);
$writeObj
=
[
"id"
=>
$tc
->
id
,
"latex"
=>
$tc
->
latex
,
"latexi"
=>
$tc
->
latexi
,
"MathML_texvc"
=>
$mathMLtexVC
,
"MathML_default"
=>
$tc
->
mathML_default
,
"MathML_explicit"
=>
$tc
->
mathML_explicit
,
"Name"
=>
$tc
->
name
,
];
self
::
writeToJSONFile
(
$writeObj
,
$tc
->
ctr
!=
86
?
true
:
false
);
$this
->
addToAssertionCount
(
1
);
}
public
static
function
provideTestCases
()
{
$resIntent
=
MMLTestUtil
::
getJSON
(
self
::
$FILENAMEINTENTTESTS
);
$resIntent2
=
MMLTestUtil
::
getJSON
(
self
::
$FILENAMEINTENTANNOTATED
);
$f
=
[];
// Adding running indices for location of tests.
foreach
(
$resIntent
as
$index
=>
$tcIntent
)
{
$tcIntent
->
ctr
=
$index
;
$tcIntent2
=
$resIntent2
[
$index
];
$tcIntent
->
latexi
=
isset
(
$tcIntent2
->
latexi
)
?
$tcIntent2
->
latexi
:
""
;
$tcIntent
->
shouldfail
=
isset
(
$tcIntent2
->
shouldfail
)
?
$tcIntent2
->
shouldfail
:
false
;
$tcIntent
->
skipped
=
isset
(
$tcIntent2
->
skipped
)
?
$tcIntent2
->
skipped
:
false
;
$tcIntent
->
usemhchem
=
isset
(
$tcIntent2
->
usemhchem
)
?
$tcIntent2
->
usemhchem
:
false
;
array_push
(
$f
,
[
$tcIntent
->
name
,
(
object
)
$tcIntent
]
);
}
// Filtering results by index if necessary
if
(
self
::
$APPLYFILTER
)
{
$f
=
array_slice
(
$f
,
self
::
$FILTERSTART
,
self
::
$FILTERLENGTH
);
}
return
$f
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 21:16 (1 d, 15 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
5f/b2/81eab3015ca57f53dce42a808a49
Default Alt Text
IntentParserTest.php (4 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment