Skip to content

Commit

Permalink
updated homonym finder
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnPConroy committed Aug 10, 2020
1 parent 7f57b24 commit a31e894
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .php_cs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"php":"5.6.35","version":"2.16.1","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"index.php":3351273838,"src\/App.php":2229694930,"src\/config.php":2514023755,"src\/request.php":1078107796,"src\/WorldlangDictUtils.php":387099823,"src\/Parsedown.php":3204335427,"src\/test-ipa.php":3271240354,"templates\/boilerplate\/index.php":2301605749,"templates\/menalar\/index.php":3806569683,"templates\/identity\/index.php":544792056,"templates\/photon\/index.php":4187379909,"models\/WordList.php":2484934148,"models\/Word.php":2613674344,"models\/Request.php":1680315779,"controllers\/ToolController.php":2710750231,"controllers\/IndexController.php":580255643,"controllers\/SearchController.php":2541276491,"controllers\/WordListController.php":3775586406,"src\/router.php":3067629955,"models\/Page.php":4038198180,"models\/WorldlangDictConfig.php":677662292,"views\/IndexView.php":2999675711,"views\/WordView.php":2610577676,"views\/SearchView.php":501353686,"views\/indexView.php":2882736464,"views\/ToolView.php":1292037398,"views\/WordListView.php":633425177,"controllers\/WordController.php":323154340}}
{"php":"5.6.35","version":"2.16.1","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"index.php":3662487177,"src\/App.php":2229694930,"src\/config.php":2514023755,"src\/request.php":1078107796,"src\/WorldlangDictUtils.php":387099823,"src\/Parsedown.php":3204335427,"src\/test-ipa.php":3271240354,"templates\/boilerplate\/index.php":2301605749,"templates\/menalar\/index.php":2281042646,"templates\/identity\/index.php":544792056,"templates\/photon\/index.php":4187379909,"models\/WordList.php":2484934148,"models\/Word.php":1557902953,"models\/Request.php":177841749,"controllers\/ToolController.php":155173001,"controllers\/IndexController.php":905856578,"controllers\/SearchController.php":307256060,"controllers\/WordListController.php":2768928106,"src\/router.php":3067629955,"models\/Page.php":4038198180,"models\/WorldlangDictConfig.php":677662292,"views\/IndexView.php":2377744807,"views\/WordView.php":555201782,"views\/SearchView.php":2364620608,"views\/indexView.php":2882736464,"views\/ToolView.php":2465482814,"views\/WordListView.php":633425177,"controllers\/WordController.php":808365098,"config.php":106939348,"WorldlangDictUtils.php":3740432248,"models\/Tool.php":2087329458,"router.php":445095620,"bootstrap.php":2008436989}}
9 changes: 4 additions & 5 deletions WorldlangDictUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ public static function makeUri($config, $controller)
return $config->siteUri.$config->lang.'/'.$controller.$request->linkQuery;
}

public static function changeLangUri($config, $request, $lang) {
public static function changeLangUri($config, $request, $lang)
{
if (is_null($request->arguments)) {
$args = '';
}
else if (sizeof($request->arguments) == 1) {
} elseif (sizeof($request->arguments) == 1) {
$args = $request->arguments[0];
}
else {
} else {
$args = implode('/', $request->arguments);
}
return $config->siteUri.$lang.'/'
Expand Down
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
include_once './controllers/IndexController.php';

$config = new WorldlangDictConfig();
include_once './config.php';
include_once './config.php';
7 changes: 4 additions & 3 deletions controllers/ToolController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ public static function run($config, $request, &$page)
$page->setTitle($config->getTrans('tools button'));
}

public static function minimalPairDetector($config, $request, &$page) {
public static function minimalPairDetector($config, $request, &$page)
{
$nearMatches = Tool::minimalPairDetector($config, $request);
ToolView::minimalPairDetector($config, $request, $nearMatches, $page);
$page->setTitle($config->getTrans('minimum pair title'));
}

public static function homonymTerminator($config, $request, &$page) {
public static function homonymTerminator($config, $request, &$page)
{
$genWords = Tool::homonymTerminator($config, $request);
ToolView::homonymTerminator($config, $request, $genWords, $page);
$page->setTitle($config->getTrans('homonym terminator title'));
}

}
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
namespace WorldlangDict;

include_once 'bootstrap.php';
router($config);
router($config);
61 changes: 37 additions & 24 deletions models/Tool.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,62 @@
<?php
namespace WorldlangDict;

class Tool {

public static function homonymTerminator($config, $request) {

// Create arrays for 3 category types
class Tool
{
public static function homonymTerminator($config, $request)
{

// Add the new root candidate
if (isset($request->options['root']) && !empty($request->options['root'])) {
$root[] = $newRoot = $request->options['root'];
$genList[$newRoot][$newRoot] = "|$newRoot|";
}

// Create arrays for 3 category types, put all roots in genList.
foreach ($config->dictionary[$config->worldlang] as $word=>$entry) {
if ($entry['Category']=='root') {
$root[]=$word;
$genList[$word][$currentRoot] = 'Root';
$genList[$word]["|$word|"] = "|$word|";
} elseif ($entry['Category']=='affix' && $word[0]=='-') {
$suffix[]= $word;
} elseif ($entry['Category']=='affix') {
$prefix[] = $word;
}
}

// Add the new root
if (isset($request->options['root']) && !empty($request->options['root'])) {
$root[] = $request->options['root'];
}

// Generate all word combinations

// Generate all combinations, duplicate if combos on duplicate letter
foreach ($root as $currentRoot) {
foreach ($suffix as $currentSuffix) {
$genWord = $currentRoot.substr($currentSuffix, 1);
$genList[$genWord][$currentRoot] = "$currentRoot-$currentSuffix";
}
foreach ($prefix as $currentPrefix) {
$genWord = substr($currentPrefix, 0, -1).$currentRoot;
$genList[$genWord][$currentRoot] = "$currentPrefix-$currentRoot";
$genList[$genWord][$currentRoot] = "$currentPrefix-|$currentRoot|";

if (substr($currentPrefix, -2, 1) == $currentRoot[0]) {
$genWord = substr($currentPrefix, 0, -2) . $currentRoot;
$genList[$genWord][$currentRoot] = "$currentPrefix-|$currentRoot|";
}
}
foreach ($suffix as $currentSuffix) {
$genWord = $currentRoot.substr($currentSuffix, 1);
$genList[$genWord][$currentRoot] = "|$currentRoot|-$currentSuffix";

if (substr($currentRoot, -1) == $currentSuffix[1]) {
$genWord = $currentRoot.substr($currentSuffix, 2);
$genList[$genWord][$currentRoot] = "|$currentRoot|-$currentSuffix";
}
}
}
ksort($genList);

return $genList;
}

public static function minimalPairDetector ($config, $request) {

public static function minimalPairDetector($config, $request)
{
$words = array_keys($config->dictionary[$config->worldlang]);
$numWords = sizeof($words);
$nearMatches = [];
$checkWord = isset($request->options['word']) ? strtolower($request->options['word']) : null;

if (empty($checkWord)) {
for ($i = 0; $i < $numWords; $i++) {
for ($j = $i+1; $j < $numWords; $j++) {
Expand All @@ -61,7 +74,7 @@ public static function minimalPairDetector ($config, $request) {
}
}
}

return $nearMatches;
}
}
}
7 changes: 4 additions & 3 deletions models/Word.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public function __construct($config, $data)
$this->ipa($config);
}

private function processEtymology($config) {
if(strpos($this->etymology, '+')) {
private function processEtymology($config)
{
if (strpos($this->etymology, '+')) {
$words = explode(' + ', $this->etymology);
foreach($words as $word) {
foreach ($words as $word) {
$links[] = WorldlangDictUtils::makeLink($config, 'leksi/'.$word, $word);
}
$this->etymology = implode(' + ', $links);
Expand Down
1 change: 1 addition & 0 deletions templates/menalar/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace WorldlangDict;

?>
<!doctype html>
<html class="no-js" lang="">
Expand Down
34 changes: 18 additions & 16 deletions views/ToolView.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class ToolView
public static function toolList($config, &$page)
{
$page->content .= '<h1>'.$config->getTrans('tools button').'</h1>
<div class="w3-card">
<header class="w3-container w3-blue">
<h2><a href="'.WorldlangDictUtils::makeUri($config, 'tule/homonym-terminator').'">'.$config->getTrans('homonym terminator title').'</a></h2>
</header>
<div class="w3-container"><p>'.$config->getTrans('homonym terminator description').'</p>
</div>
</div>
<div class="w3-card">
<header class="w3-container w3-blue">
<h2><a href="'.WorldlangDictUtils::makeUri($config, 'tule/minimal-pair-detector').'">'.$config->getTrans('minimum pair title').'</a></h2>
Expand All @@ -24,8 +24,9 @@ public static function toolList($config, &$page)
</div>
';
}

public static function homonymTerminator($config, $request, $genList, &$page) {

public static function homonymTerminator($config, $request, $genList, &$page)
{
$page->content .= '<h1>'.$config->getTrans('homonym terminator title').'</h1>';
$page->content .= '
<div class="w3-card w3-container" style="padding: 5px">
Expand All @@ -34,25 +35,26 @@ public static function homonymTerminator($config, $request, $genList, &$page) {
<input type="submit" class="w3-btn w3-blue-grey" />
</form>
</div>';

foreach ($genList as $genWord=>$genRoots) {
if (sizeof($genRoots)>1 && (!isset($request->options['root']) || isset($genRoots[$request->options['root']]))) {

foreach ($genList as $genWord=>$sources) {
// Show all or only show ones related to the root.
if (sizeof($sources)>1 && (!isset($request->options['root']) || isset($sources[$request->options['root']]))) {
if (isset($config->dictionary['glb'][$genWord])) {
$definition = '</br>'.$config->dictionary['glb'][$genWord][DefinitionEng];
} else {
$definition = "";
}
$page->content .= '<li><span style="font-weight: bold; font-size: larger;">'.$genWord."</span><br />".$config->getTrans('homonym terminator conflicting msg').
" ". implode($genRoots, ', ').$definition."</li>";
$page->content .= '<li><span style="font-weight: bold; font-size: larger;">['.$genWord."]</span><br />".$config->getTrans('homonym terminator conflicting msg').
" ". implode($sources, ', ').$definition."</li>";
}
}
$page->content .= "</ul>";
}
public static function minimalPairDetector ($config, $request, $nearMatches, &$page) {

public static function minimalPairDetector($config, $request, $nearMatches, &$page)
{
$searchTerm = isset($request->options['word']) ? $request->options['word'] : "";

$page->content = '';
$page->content .= '<h1>'.$config->getTrans('minimum pair title').'</h1>';
$page->content .= '
Expand All @@ -63,9 +65,9 @@ public static function minimalPairDetector ($config, $request, $nearMatches, &$p
</form>
</div>
';

$numWords = sizeof($words);

foreach ($nearMatches as $word=>$data) {
foreach ($data as $match=>$distance) {
if ($distance == 1) {
Expand All @@ -76,7 +78,7 @@ public static function minimalPairDetector ($config, $request, $nearMatches, &$p
}
}
}

$page->content .='<h2>'.sprintf($config->getTrans('minimum pair result diff', '1')).'</h2>
<ul>'.$d1.'</ul>
<h2>'.sprintf($config->getTrans('minimum pair result diff', '2')).'</h2>
Expand Down

0 comments on commit a31e894

Please sign in to comment.