ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
WordLevelDiff Class Reference
+ Inheritance diagram for WordLevelDiff:
+ Collaboration diagram for WordLevelDiff:

Public Member Functions

 __construct ($orig_lines, $closing_lines)
 Constructor. More...
 
 _split ($lines)
 
 orig ()
 Get the original set of lines. More...
 
 closing ()
 Get the closing set of lines. More...
 
- Public Member Functions inherited from MappedDiff
 __construct ( $from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)
 Constructor. More...
 
- Public Member Functions inherited from Diff
 __construct ($from_lines, $to_lines)
 Constructor. More...
 
 reverse ()
 Compute reversed Diff. More...
 
 isEmpty ()
 Check for empty diff. More...
 
 lcs ()
 Compute the length of the Longest Common Subsequence (LCS). More...
 
 orig ()
 Get the original set of lines. More...
 
 closing ()
 Get the closing set of lines. More...
 
 _check ($from_lines, $to_lines)
 Check a Diff for validity. More...
 

Data Fields

const MAX_LINE_LENGTH = 10000
 
- Data Fields inherited from Diff
 $edits
 

Detailed Description

Definition at line 1099 of file class.WordLevelDiff.php.

Constructor & Destructor Documentation

◆ __construct()

WordLevelDiff::__construct (   $from_lines,
  $to_lines 
)

Constructor.

Computes diff between sequences of strings.

Parameters
$from_linesarray An array of strings. (Typically these are lines from a file.)
$to_linesarray An array of strings.

Reimplemented from Diff.

Definition at line 1103 of file class.WordLevelDiff.php.

1104 {
1105 $fname = 'WordLevelDiff::WordLevelDiff';
1106 //wfProfileIn( $fname );
1107
1108 list($orig_words, $orig_stripped) = $this->_split($orig_lines);
1109 list($closing_words, $closing_stripped) = $this->_split($closing_lines);
1110
1112 $orig_words,
1113 $closing_words,
1114 $orig_stripped,
1115 $closing_stripped
1116 );
1117 //wfProfileOut( $fname );
1118 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), and _split().

+ Here is the call graph for this function:

Member Function Documentation

◆ _split()

WordLevelDiff::_split (   $lines)

Definition at line 1120 of file class.WordLevelDiff.php.

1121 {
1122 $fname = 'WordLevelDiff::_split';
1123 //wfProfileIn( $fname );
1124
1125 $words = array();
1126 $stripped = array();
1127 $first = true;
1128 foreach ($lines as $line) {
1129 # If the line is too long, just pretend the entire line is one big word
1130 # This prevents resource exhaustion problems
1131 if ($first) {
1132 $first = false;
1133 } else {
1134 $words[] = "\n";
1135 $stripped[] = "\n";
1136 }
1137 if (strlen($line) > self::MAX_LINE_LENGTH) {
1138 $words[] = $line;
1139 $stripped[] = $line;
1140 } else {
1141 $m = array();
1142 if (preg_match_all(
1143 '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
1144 $line,
1145 $m
1146 )) {
1147 $words = array_merge($words, $m[0]);
1148 $stripped = array_merge($stripped, $m[1]);
1149 }
1150 }
1151 }
1152 //wfProfileOut( $fname );
1153 return array($words, $stripped);
1154 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ closing()

WordLevelDiff::closing ( )

Get the closing set of lines.

This reconstructs the $to_lines parameter passed to the constructor.

Returns
array The sequence of strings.

Reimplemented from Diff.

Definition at line 1174 of file class.WordLevelDiff.php.

1175 {
1176 $fname = 'WordLevelDiff::closing';
1177 //wfProfileIn( $fname );
1178 $closing = new _HWLDF_WordAccumulator();
1179
1180 foreach ($this->edits as $edit) {
1181 if ($edit->type == 'copy') {
1182 $closing->addWords($edit->closing);
1183 } elseif ($edit->closing) {
1184 $closing->addWords($edit->closing, 'ins');
1185 }
1186 }
1187 $lines = $closing->getLines();
1188 //wfProfileOut( $fname );
1189 return $lines;
1190 }

◆ orig()

WordLevelDiff::orig ( )

Get the original set of lines.

This reconstructs the $from_lines parameter passed to the constructor.

Returns
array The original sequence of strings.

Reimplemented from Diff.

Definition at line 1156 of file class.WordLevelDiff.php.

1157 {
1158 $fname = 'WordLevelDiff::orig';
1159 //wfProfileIn( $fname );
1160 $orig = new _HWLDF_WordAccumulator();
1161
1162 foreach ($this->edits as $edit) {
1163 if ($edit->type == 'copy') {
1164 $orig->addWords($edit->orig);
1165 } elseif ($edit->orig) {
1166 $orig->addWords($edit->orig, 'del');
1167 }
1168 }
1169 $lines = $orig->getLines();
1170 //wfProfileOut( $fname );
1171 return $lines;
1172 }

Field Documentation

◆ MAX_LINE_LENGTH

const WordLevelDiff::MAX_LINE_LENGTH = 10000

Definition at line 1101 of file class.WordLevelDiff.php.


The documentation for this class was generated from the following file: