[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Highlight recited sentence

2017-03-03 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/336816 )

Change subject: Highlight recited sentence
..


Highlight recited sentence

Added highlighting to the sentence that is currently being recited,
using span elements. The highlighting visuals can be changed by
overriding `.ext-wikispeech-highlight-sentence`. The default value is
defined in modules/ext.wikispeech.css. All text nodes used to generate
the utterance is wrapped in spans, except for the first and last. For
the latter, only the range of the node which is used in the utterance
is wrapped.

A `path` attribute was introduced to make the connection from an
utterance to the text nodes that were used to generate it. In doing
this, it was discovered that the position attributes previously added
to both utterances and tokens, aren't used in this solution. They were
therefore removed. This also allowed the removal of some
functionality, that was added for positions to work.

With the introduction of text elements, CleanedTag was renamed
CleanedContent and CleanedText was added. All the types of tags
(start-, end- and empty-) are now represented by the same class,
CleanedTag.

Tests were changed a bit to have less overlap in what's being tested
and to make them easier to work with.

Bug: T148622
Change-Id: I12c8873265b7236c0677b25ce089bbb887ffdd9c
---
M Doxyfile
M extension.json
A includes/CleanedContent.php
D includes/CleanedTag.php
M includes/Cleaner.php
M includes/HtmlGenerator.php
M includes/Segmenter.php
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/phpunit/CleanerTest.php
M tests/phpunit/HtmlGeneratorTest.php
M tests/phpunit/SegmenterTest.php
M tests/phpunit/Util.php
M tests/qunit/ext.wikispeech.test.js
14 files changed, 1,029 insertions(+), 728 deletions(-)

Approvals:
  Lokal Profil: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Doxyfile b/Doxyfile
index e5066f6..20b639f 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -10,11 +10,11 @@
 
 QUIET  = YES
 WARNINGS   = YES
-WARN_IF_UNDOCUMENTED   = NO
+WARN_IF_UNDOCUMENTED   = YES
 WARN_IF_DOC_ERROR  = NO
-WARN_NO_PARAMDOC   = NO
+WARN_NO_PARAMDOC   = YES
 
-EXCLUDE= docs vendor node_modules
+EXCLUDE= docs vendor node_modules tests
 FILE_PATTERNS  = *.php
 RECURSIVE  = YES
 
diff --git a/extension.json b/extension.json
index 7917c45..ab1e6a8 100644
--- a/extension.json
+++ b/extension.json
@@ -18,10 +18,9 @@
"AutoloadClasses": {
"SpecialWikispeech": "specials/SpecialWikispeech.php",
"WikispeechHooks": "Hooks.php",
-   "CleanedTag": "includes/CleanedTag.php",
-   "CleanedStartTag": "includes/CleanedTag.php",
-   "CleanedEndTag": "includes/CleanedTag.php",
-   "CleanedEmptyElementTag": "includes/CleanedTag.php",
+   "CleanedContent": "includes/CleanedContent.php",
+   "CleanedTag": "includes/CleanedContent.php",
+   "CleanedText": "includes/CleanedContent.php",
"Cleaner": "includes/Cleaner.php",
"HtmlGenerator": "includes/HtmlGenerator.php",
"Segmenter": "includes/Segmenter.php"
diff --git a/includes/CleanedContent.php b/includes/CleanedContent.php
new file mode 100644
index 000..3065afd
--- /dev/null
+++ b/includes/CleanedContent.php
@@ -0,0 +1,77 @@
+string = $string;
+   }
+}
+
+class CleanedTag extends CleanedContent {
+}
+
+class CleanedText extends CleanedContent {
+   /**
+* The path in the HTML to the text node that this was created
+* from. The path consists of indices of the elements leading to
+* the text node, and the index of the text node itself.
+*
+* @var array $path
+*/
+
+   public $path;
+
+   /**
+* Create a CleanedText, given a string representation.
+*
+* If the path isn't set, it defaults to the empty array.
+*
+* @since 0.0.1
+* @param string $string The string representation of this text.
+* @param array $path The path to the text node this was created from.
+*/
+
+   function __construct( $string, $path=[] ) {
+   parent::__construct( $string );
+   $this->path = $path;
+   }
+
+   /**
+* Create a Text element from the content.
+*
+* Path is converted to a string and added as an attribute.
+*
+* @since 0.0.1
+* @param DOMDocument $dom The DOM Document used to create the element.
+* @return DOMElement The created text element.
+*/
+
+   function toElement( $dom ) {
+   $element = $dom->createElement( 'text', $this->string );
+   $pathString = implode( $this->path, ',' );
+   $element->setAttribute( 'path', 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Highlight recited sentence

2017-02-09 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/336816 )

Change subject: Highlight recited sentence
..

Highlight recited sentence

Added highlighting to the sentence that is currently being recited,
using span elements. The highlighting visuals can be changed in
modules/ext.wikispeech.css. All text nodes that were used to generate
the utterance is wrapped in spans, except for the first and
last. These only get the ranges used as part of the utterance wrapped.

A `path` attribute was introduced to make the connection from an
utterance to the text nodes that were used to generate it. In doing
this, it was discovered that the position attributes, that were
previously added to both utterances and tokens, aren't used in this
solution. They were therefore removed.

Tests were changed a bit to have less overlap in what's being tested
and to make them easier to work with.

Bug: T148622
Change-Id: I12c8873265b7236c0677b25ce089bbb887ffdd9c
---
A includes/CleanedContent.php
D includes/CleanedTag.php
M includes/Cleaner.php
M includes/HtmlGenerator.php
M includes/Segmenter.php
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/phpunit/CleanerTest.php
M tests/phpunit/HtmlGeneratorTest.php
M tests/phpunit/SegmenterTest.php
M tests/phpunit/Util.php
M tests/qunit/ext.wikispeech.test.js
12 files changed, 962 insertions(+), 629 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/16/336816/1

diff --git a/includes/CleanedContent.php b/includes/CleanedContent.php
new file mode 100644
index 000..4d123b3
--- /dev/null
+++ b/includes/CleanedContent.php
@@ -0,0 +1,52 @@
+string = $string;
+   }
+}
+
+class CleanedTag extends CleanedContent {
+}
+
+class Text extends CleanedContent {
+   public $path;
+
+   function __construct( $string, $path=[] ) {
+   parent::__construct( $string );
+   $this->path = $path;
+   }
+
+   /**
+* Create a Text element from the content.
+*
+* Path is converted to a string and added as an attribute.
+*
+* @since 0.0.1
+* @param DOMDocument $dom The DOM Document used to create the element.
+* @return DOMElement The length of the tag string.
+*/
+
+   function toElement( $dom ) {
+   $element = $dom->createElement( 'text', $this->string );
+   $pathString = implode( $this->path, ',' );
+   $element->setAttribute( 'path', $pathString );
+   return $element;
+   }
+}
diff --git a/includes/CleanedTag.php b/includes/CleanedTag.php
deleted file mode 100644
index 697032c..000
--- a/includes/CleanedTag.php
+++ /dev/null
@@ -1,73 +0,0 @@
-tagString = $tagString;
-   }
-
-   /**
-* Get the length of the tag string.
-*
-* @since 0.0.1
-* @return int The length of the tag string.
-*/
-
-   function getLength() {
-   return strlen( $this->tagString );
-   }
-}
-
-class CleanedStartTag extends CleanedTag {
-
-   /**
-* The length of the element content, i.e. the string delimited by
-* this start tag and the corresponding end tag.
-*
-* @var int $contentLength
-*/
-
-   public $contentLength;
-
-   function __construct( $tagString ) {
-   parent::__construct( $tagString );
-   $this->contentLength = 0;
-   }
-
-   /**
-* Get the length of the tag string.
-*
-* @since 0.0.1
-* @return int The length of the tag string, including element content.
-*/
-
-   function getLength() {
-   $length = strlen( $this->tagString );
-   if ( $this->contentLength ) {
-   $length += $this->contentLength;
-   }
-   return $length;
-   }
-}
-
-class CleanedEndTag extends CleanedTag {
-}
-
-class CleanedEmptyElementTag extends CleanedTag {
-}
diff --git a/includes/Cleaner.php b/includes/Cleaner.php
index e7b4a1f..dc547f6 100644
--- a/includes/Cleaner.php
+++ b/includes/Cleaner.php
@@ -6,7 +6,7 @@
  * @license GPL-2.0+
  */
 
-require_once 'CleanedTag.php';
+require_once 'CleanedContent.php';
 
 class Cleaner {
 
@@ -35,7 +35,8 @@
$dom->documentElement->firstChild,
$markedUpText,
$tags,
-   $tagIndex
+   $tagIndex,
+   []
);
return $cleanedContent;
}
@@ -73,14 +74,12 @@
 * regex since we need the exact string representation of tags to
 * get their correct lengths.
 *
-* When a start tag is encountered, it's stored as an array
-* containing the tag string and the start position of the
-* tag. This array is