Алгоритмы для выполнения операций, необходимых для синхронизации обычного текста
Версия: 1.0
Дата релиза: 16.06.2023
Получает различия без очистки.
Описание возврата: Возвращает текст с различиями
Примеры использования<?php
// инициализация
$xhe_host = '127.0.0.1:7010';
$relative_app_dir = '..\\..\\..\\';
require($relative_app_dir.'Templates/init.php');
include($relative_app_dir.'Templates/_for_tests_.php');
$bUTF8Ver = true;
$PHP_Use_Trought_Shell = true;
// рабочая папка
$script_folder = $debug->get_cur_script_folder();
// отсносительный путь
$app_dir = realpath($script_folder.$relative_app_dir);
// тестовые данные
$test = new _for_tests_($script_folder, $diffmatchpatch);
// начало теста
$test->echo_header('diff_no_clenup');
echo 'Text Version 1:'."\n\n";
$text_v1_path = $test->get_test_file_full_path('first_input_test_file.txt');
$text_v1 = $test->read_all_text_from_file($text_v1_path);
echo $text_v1."\n";
echo "\n".'\nText Version 2:'."\n\n";
$text_v2_path = $test->get_test_file_full_path('second_input_test_file.txt');
$text_v2 = $test->read_all_text_from_file($text_v2_path);
echo $text_v2."\n";
echo "\n".'\nDiff result:'."\n\n";
echo $diffmatchpatch->diff_no_clenup($text_v1_path, $text_v2_path)."\n";
// конец теста
echo "\n<hr><br>";
// выход
$app->quit();
?>
// связь с платформой
xhe_host = '127.0.0.1:7014'
_path = require('path')
relative_app_dir = '..\\..\\..\\'
echo = require(_path.join(relative_app_dir, 'Templates JS', 'init.js'))
_for_tests_ = require(_path.join(relative_app_dir, 'Templates JS', '_for_tests_.js'))
// рабочая папка
script_folder = debug.get_cur_script_folder()
// отсносительны йпуть
app_dir = _path.resolve(_path.join(script_folder, relative_app_dir))
// тестовые данные
test = new _for_tests_(script_folder, diffmatchpatch)
// начало теста
test.echo_header('diff_no_clenup')
echo('Text Version 1:\n\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
echo(`${text_v1}\n`)
echo('\n\nText Version 2:\n\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
echo(`${text_v2}\n`)
echo('\n\nDiff result:\n\n')
echo(`${diffmatchpatch.diff_no_clenup(text_v1_path, text_v2_path)}\n`)
// конец теста
echo('\n<hr><br>')
// выход
app.quit()
# дополнительные пути
import sys, os
relative_app_dir = '..\\..\\..\\'
sys.path.append(os.path.join(relative_app_dir, 'Templates PY'))
# связь с платофрмой
xhe_host = '127.0.0.1:7010'
from xweb_human_emulator import *
from _for_tests_ import _for_tests_
# рабочая папка
script_folder = debug.get_cur_script_folder()
# относительный путь
app_dir = os.path.abspath(os.path.join(script_folder, relative_app_dir))
# тестовые данные
test = _for_tests_(script_folder, diffmatchpatch)
# начало теста
test.echo_header('diff_no_clenup')
print('Text Version 1:\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
print(text_v1)
print('\n\nText Version 2:\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
print(text_v2)
print('\n\nDiff result:\n')
print(diffmatchpatch.diff_no_clenup(text_v1_path, text_v2_path))
# конец теста
print('\n<hr><br>')
# выход
app.quit()
Получает различия с повышением удобочитаемости текста путем исключения общих черт, которые могут быть случайными.
Описание возврата: Возвращает текст с различиями
Примеры использования<?php
// инициализация
$xhe_host = '127.0.0.1:7010';
$relative_app_dir = '..\\..\\..\\';
require($relative_app_dir.'Templates/init.php');
include($relative_app_dir.'Templates/_for_tests_.php');
$bUTF8Ver = true;
$PHP_Use_Trought_Shell = true;
// рабочая папка
$script_folder = $debug->get_cur_script_folder();
// отсносительный путь
$app_dir = realpath($script_folder.$relative_app_dir);
// тестовые данные
$test = new _for_tests_($script_folder, $diffmatchpatch);
// начало теста
$test->echo_header('diff_clenup_semantic');
echo 'Text Version 1:'."\n\n";
$text_v1_path = $test->get_test_file_full_path('first_input_test_file.txt');
$text_v1 = $test->read_all_text_from_file($text_v1_path);
echo $text_v1."\n";
echo "\n".'\nText Version 2:'."\n\n";
$text_v2_path = $test->get_test_file_full_path('second_input_test_file.txt');
$text_v2 = $test->read_all_text_from_file($text_v2_path);
echo $text_v2."\n";
echo "\n".'\nDiff result:'."\n\n";
echo $diffmatchpatch->diff_clenup_semantic($text_v1_path, $text_v2_path)."\n";
// конец теста
echo "\n<hr><br>";
// выход
$app->quit();
?>
// связь с платформой
xhe_host = '127.0.0.1:7014'
_path = require('path')
relative_app_dir = '..\\..\\..\\'
echo = require(_path.join(relative_app_dir, 'Templates JS', 'init.js'))
_for_tests_ = require(_path.join(relative_app_dir, 'Templates JS', '_for_tests_.js'))
// рабочая папка
script_folder = debug.get_cur_script_folder()
// отсносительны йпуть
app_dir = _path.resolve(_path.join(script_folder, relative_app_dir))
// тестовые данные
test = new _for_tests_(script_folder, diffmatchpatch)
// начало теста
test.echo_header('diff_clenup_semantic')
echo('Text Version 1:\n\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
echo(`${text_v1}\n`)
echo('\n\nText Version 2:\n\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
echo(`${text_v2}\n`)
echo('\n\nDiff result:\n\n')
echo(`${diffmatchpatch.diff_clenup_semantic(text_v1_path, text_v2_path)}\n`)
// конец теста
echo('\n<hr><br>')
// выход
app.quit()
# дополнительные пути
import sys, os
relative_app_dir = '..\\..\\..\\'
sys.path.append(os.path.join(relative_app_dir, 'Templates PY'))
# связь с платофрмой
xhe_host = '127.0.0.1:7010'
from xweb_human_emulator import *
from _for_tests_ import _for_tests_
# рабочая папка
script_folder = debug.get_cur_script_folder()
# относительный путь
app_dir = os.path.abspath(os.path.join(script_folder, relative_app_dir))
# тестовые данные
test = _for_tests_(script_folder, diffmatchpatch)
# начало теста
test.echo_header('diff_clenup_semantic')
print('Text Version 1:\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
print(text_v1)
print('\n\nText Version 2:\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
print(text_v2)
print('\n\nDiff result:\n')
print(diffmatchpatch.diff_clenup_semantic(text_v1_path, text_v2_path))
# конец теста
print('\n<hr><br>')
# выход
app.quit()
Получает различия с повышением эффективности вычислений путем удаления коротких общих черт, которые не стоят накладных расходов. Чем больше стоимость редактирования, тем агрессивнее очистка.
Описание возврата: Возвращает текст с различиями
Примеры использования<?php
// инициализация
$xhe_host = '127.0.0.1:7010';
$relative_app_dir = '..\\..\\..\\';
require($relative_app_dir.'Templates/init.php');
include($relative_app_dir.'Templates/_for_tests_.php');
$bUTF8Ver = true;
$PHP_Use_Trought_Shell = true;
// рабочая папка
$script_folder = $debug->get_cur_script_folder();
// отсносительный путь
$app_dir = realpath($script_folder.$relative_app_dir);
// тестовые данные
$test = new _for_tests_($script_folder, $diffmatchpatch);
// начало теста
$test->echo_header('diff_clenup_efficiency');
echo 'Text Version 1:'."\n\n";
$text_v1_path = $test->get_test_file_full_path('first_input_test_file.txt');
$text_v1 = $test->read_all_text_from_file($text_v1_path);
echo $text_v1."\n";
echo "\n".'\nText Version 2:'."\n\n";
$text_v2_path = $test->get_test_file_full_path('second_input_test_file.txt');
$text_v2 = $test->read_all_text_from_file($text_v2_path);
echo $text_v2."\n";
echo "\n".'\nDiff result:'."\n\n";
echo $diffmatchpatch->diff_clenup_efficiency($text_v1_path, $text_v2_path, 4)."\n";
// конец теста
echo "\n<hr><br>";
// выход
$app->quit();
?>
// связь с платформой
xhe_host = '127.0.0.1:7014'
_path = require('path')
relative_app_dir = '..\\..\\..\\'
echo = require(_path.join(relative_app_dir, 'Templates JS', 'init.js'))
_for_tests_ = require(_path.join(relative_app_dir, 'Templates JS', '_for_tests_.js'))
// рабочая папка
script_folder = debug.get_cur_script_folder()
// отсносительны йпуть
app_dir = _path.resolve(_path.join(script_folder, relative_app_dir))
// тестовые данные
test = new _for_tests_(script_folder, diffmatchpatch)
// начало теста
test.echo_header('diff_clenup_efficiency')
echo('Text Version 1:\n\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
echo(`${text_v1}\n`)
echo('\n\nText Version 2:\n\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
echo(`${text_v2}\n`)
echo('\n\nDiff result:\n\n')
echo(`${diffmatchpatch.diff_clenup_efficiency(text_v1_path, text_v2_path, 4)}\n`)
// конец теста
echo('\n<hr><br>')
// выход
app.quit()
# дополнительные пути
import sys, os
relative_app_dir = '..\\..\\..\\'
sys.path.append(os.path.join(relative_app_dir, 'Templates PY'))
# связь с платофрмой
xhe_host = '127.0.0.1:7010'
from xweb_human_emulator import *
from _for_tests_ import _for_tests_
# рабочая папка
script_folder = debug.get_cur_script_folder()
# относительный путь
app_dir = os.path.abspath(os.path.join(script_folder, relative_app_dir))
# тестовые данные
test = _for_tests_(script_folder, diffmatchpatch)
# начало теста
test.echo_header('diff_clenup_efficiency')
print('Text Version 1:\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
print(text_v1)
print('\n\nText Version 2:\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
print(text_v2)
print('\n\nDiff result:\n')
print(diffmatchpatch.diff_clenup_efficiency(text_v1_path, text_v2_path, 4))
# конец теста
print('\n<hr><br>')
# выход
app.quit()
Выполняет поиск шаблона в тексте большего размера. Эта реализация match является нечеткой, что означает, что она может найти совпадение, даже если шаблон содержит ошибки и не совсем соответствует тому, что найдено в тексте. Эта реализация также принимает ожидаемое местоположение, рядом с которым должно быть найдено совпадение.
Описание возврата: Возвращает номер символа
Примеры использования<?php
// инициализация
$xhe_host = '127.0.0.1:7010';
$relative_app_dir = '..\\..\\..\\';
require($relative_app_dir.'Templates/init.php');
include($relative_app_dir.'Templates/_for_tests_.php');
$bUTF8Ver = true;
$PHP_Use_Trought_Shell = true;
// рабочая папка
$script_folder = $debug->get_cur_script_folder();
// отсносительный путь
$app_dir = realpath($script_folder.$relative_app_dir);
// тестовые данные
$test = new _for_tests_($script_folder, $diffmatchpatch);
// начало теста
$test->echo_header('match');
echo 'Text:'."\n\n";
$text_v1_path = $test->get_test_file_full_path('first_input_test_file.txt');
$text_v1 = $test->read_all_text_from_file($text_v1_path);
echo $text_v1."\n";
echo "\n".'\nMatch Result:'."\n\n";
echo $diffmatchpatch->match($text_v1_path, "slimy tools", 30, 1000, 0.8)."\n";
// конец теста
echo "\n<hr><br>";
// выход
$app->quit();
?>
// связь с платформой
xhe_host = '127.0.0.1:7014'
_path = require('path')
relative_app_dir = '..\\..\\..\\'
echo = require(_path.join(relative_app_dir, 'Templates JS', 'init.js'))
_for_tests_ = require(_path.join(relative_app_dir, 'Templates JS', '_for_tests_.js'))
// рабочая папка
script_folder = debug.get_cur_script_folder()
// отсносительны йпуть
app_dir = _path.resolve(_path.join(script_folder, relative_app_dir))
// тестовые данные
test = new _for_tests_(script_folder, diffmatchpatch)
// начало теста
test.echo_header('match')
echo('Text:\n\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
echo(`${text_v1}\n`)
echo('\n\nMatch Result:\n\n')
echo(`${diffmatchpatch.match(text_v1_path, "slimy tools", 30, 1000, 0.8)}\n`)
// конец теста
echo('\n<hr><br>')
// выход
app.quit()
# дополнительные пути
import sys, os
relative_app_dir = '..\\..\\..\\'
sys.path.append(os.path.join(relative_app_dir, 'Templates PY'))
# связь с платофрмой
xhe_host = '127.0.0.1:7010'
from xweb_human_emulator import *
from _for_tests_ import _for_tests_
# рабочая папка
script_folder = debug.get_cur_script_folder()
# относительный путь
app_dir = os.path.abspath(os.path.join(script_folder, relative_app_dir))
# тестовые данные
test = _for_tests_(script_folder, diffmatchpatch)
# начало теста
test.echo_header('match')
print('Text:\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
print(text_v1)
print('\n\nMatch Result:\n')
print(diffmatchpatch.match(text_v1_path, "slimy tools", 30, 1000, 0.8))
# конец теста
print('\n<hr><br>')
# выход
app.quit()
Сопоставляет два текстовых файла друг с другом, создавая список исправлений.
Описание возврата: Возвращает текст изменений
Примеры использования<?php
// инициализация
$xhe_host = '127.0.0.1:7010';
$relative_app_dir = '..\\..\\..\\';
require($relative_app_dir.'Templates/init.php');
include($relative_app_dir.'Templates/_for_tests_.php');
$bUTF8Ver = true;
$PHP_Use_Trought_Shell = true;
// рабочая папка
$script_folder = $debug->get_cur_script_folder();
// отсносительный путь
$app_dir = realpath($script_folder.$relative_app_dir);
// тестовые данные
$test = new _for_tests_($script_folder, $diffmatchpatch);
// начало теста
$test->echo_header('patch_make');
echo 'Text Version 1:'."\n\n";
$text_v1_path = $test->get_test_file_full_path('first_input_test_file.txt');
$text_v1 = $test->read_all_text_from_file($text_v1_path);
echo $text_v1."\n";
echo "\n".'\nText Version 2:'."\n\n";
$text_v2_path = $test->get_test_file_full_path('second_input_test_file.txt');
$text_v2 = $test->read_all_text_from_file($text_v2_path);
echo $text_v2."\n";
echo "\n".'\nPatch make result:'."\n\n";
echo $diffmatchpatch->patch_make($text_v1_path, $text_v2_path)."\n";
// конец теста
echo "\n<hr><br>";
// выход
$app->quit();
?>
// связь с платформой
xhe_host = '127.0.0.1:7014'
_path = require('path')
relative_app_dir = '..\\..\\..\\'
echo = require(_path.join(relative_app_dir, 'Templates JS', 'init.js'))
_for_tests_ = require(_path.join(relative_app_dir, 'Templates JS', '_for_tests_.js'))
// рабочая папка
script_folder = debug.get_cur_script_folder()
// отсносительны йпуть
app_dir = _path.resolve(_path.join(script_folder, relative_app_dir))
// тестовые данные
test = new _for_tests_(script_folder, diffmatchpatch)
// начало теста
test.echo_header('patch_make')
echo('Text Version 1:\n\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
echo(`${text_v1}\n`)
echo('\n\nText Version 2:\n\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
echo(`${text_v2}\n`)
echo('\n\nPatch make result:\n\n')
echo(`${diffmatchpatch.patch_make(text_v1_path, text_v2_path)}\n`)
// конец теста
echo('\n<hr><br>')
// выход
app.quit()
# дополнительные пути
import sys, os
relative_app_dir = '..\\..\\..\\'
sys.path.append(os.path.join(relative_app_dir, 'Templates PY'))
# связь с платофрмой
xhe_host = '127.0.0.1:7010'
from xweb_human_emulator import *
from _for_tests_ import _for_tests_
# рабочая папка
script_folder = debug.get_cur_script_folder()
# относительный путь
app_dir = os.path.abspath(os.path.join(script_folder, relative_app_dir))
# тестовые данные
test = _for_tests_(script_folder, diffmatchpatch)
# начало теста
test.echo_header('patch_make')
print('Text Version 1:\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
print(text_v1)
print('\n\nText Version 2:\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
print(text_v2)
print('\n\nPatch make result:\n')
print(diffmatchpatch.patch_make(text_v1_path, text_v2_path))
# конец теста
print('\n<hr><br>')
# выход
app.quit()
Исправления могут быть применены к тексту. Если в тексте есть собственные правки, эта версия исправления применит свои изменения по мере возможности, сообщая, какие исправления были успешными, а какие - неудачными.
Описание возврата: Возвращает текст с примененными изменениями
Примеры использования<?php
// инициализация
$xhe_host = '127.0.0.1:7010';
$relative_app_dir = '..\\..\\..\\';
require($relative_app_dir.'Templates/init.php');
include($relative_app_dir.'Templates/_for_tests_.php');
$bUTF8Ver = true;
$PHP_Use_Trought_Shell = true;
// рабочая папка
$script_folder = $debug->get_cur_script_folder();
// отсносительный путь
$app_dir = realpath($script_folder.$relative_app_dir);
// тестовые данные
$test = new _for_tests_($script_folder, $diffmatchpatch);
// начало теста
$test->echo_header('patch_aply');
echo 'Text Version 1:'."\n\n";
$text_v1_path = $test->get_test_file_full_path('first_input_test_file.txt');
$text_v1 = $test->read_all_text_from_file($text_v1_path);
echo $text_v1."\n";
echo "\n".'\nText Version 2:'."\n\n";
$text_v2_path = $test->get_test_file_full_path('second_input_test_file.txt');
$text_v2 = $test->read_all_text_from_file($text_v2_path);
echo $text_v2."\n";
echo "\n".'\nPatches text:'."\n\n";
$patches = $diffmatchpatch->patch_make($text_v1_path, $text_v2_path);
echo $patches."\n";
echo "\n".'\nText Version 3:'."\n\n";
$text_v3_path = $test->get_test_file_full_path('thirt_input_test_file.txt');
$text_v3 = $test->read_all_text_from_file($text_v3_path);
echo $text_v3."\n";
echo "\n".'\nPatch apply result:'."\n\n";
echo $diffmatchpatch->patch_aply($text_v3_path, $patches)."\n";
// конец теста
echo "\n<hr><br>";
// выход
$app->quit();
?>
// связь с платформой
xhe_host = '127.0.0.1:7014'
_path = require('path')
relative_app_dir = '..\\..\\..\\'
echo = require(_path.join(relative_app_dir, 'Templates JS', 'init.js'))
_for_tests_ = require(_path.join(relative_app_dir, 'Templates JS', '_for_tests_.js'))
// рабочая папка
script_folder = debug.get_cur_script_folder()
// отсносительны йпуть
app_dir = _path.resolve(_path.join(script_folder, relative_app_dir))
// тестовые данные
test = new _for_tests_(script_folder, diffmatchpatch)
// начало теста
test.echo_header('patch_aply')
echo('Text Version 1:\n\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
echo(`${text_v1}\n`)
echo('\n\nText Version 2:\n\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
echo(`${text_v2}\n`)
echo('\n\nPatches text:\n\n')
patches = diffmatchpatch.patch_make(text_v1_path, text_v2_path)
echo(`${patches}\n`)
echo('\n\nText Version 3:\n\n')
text_v3_path = test.get_test_file_full_path('thirt_input_test_file.txt')
text_v3 = test.read_all_text_from_file(text_v3_path)
echo(`${text_v3}\n`)
echo('\n\nPatch apply result:\n\n')
echo(`${diffmatchpatch.patch_aply(text_v3_path, patches)}\n`)
// конец теста
echo('\n<hr><br>')
// выход
app.quit()
# дополнительные пути
import sys, os
relative_app_dir = '..\\..\\..\\'
sys.path.append(os.path.join(relative_app_dir, 'Templates PY'))
# связь с платофрмой
xhe_host = '127.0.0.1:7010'
from xweb_human_emulator import *
from _for_tests_ import _for_tests_
# рабочая папка
script_folder = debug.get_cur_script_folder()
# относительный путь
app_dir = os.path.abspath(os.path.join(script_folder, relative_app_dir))
# тестовые данные
test = _for_tests_(script_folder, diffmatchpatch)
# начало теста
test.echo_header('patch_aply')
print('Text Version 1:\n')
text_v1_path = test.get_test_file_full_path('first_input_test_file.txt')
text_v1 = test.read_all_text_from_file(text_v1_path)
print(text_v1)
print('\n\nText Version 2:\n')
text_v2_path = test.get_test_file_full_path('second_input_test_file.txt')
text_v2 = test.read_all_text_from_file(text_v2_path)
print(text_v2)
print('\n\nPatches text:\n')
patches = diffmatchpatch.patch_make(text_v1_path, text_v2_path)
print(patches)
print('\n\nText Version 3:\n')
text_v3_path = test.get_test_file_full_path('thirt_input_test_file.txt')
text_v3 = test.read_all_text_from_file(text_v3_path)
print(text_v3)
print('\n\nPatch apply result:\n')
print(diffmatchpatch.patch_aply(text_v3_path, patches))
# конец теста
print('\n<hr><br>')
# выход
app.quit()