Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion html/hurrian/commonHurrian.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
function getPos($template)
{
if ($template === 'noun' || $template === 'indecl')
if ($template === 'noun' || $template === 'indecl' || $template === '')
{
return $template;
}
Expand Down
43 changes: 18 additions & 25 deletions html/hurrian/getHurrianDictionary.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
<?php
require_once '../mysqliconn.php';
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/json');
$dbFileName = 'hurrianLexicalDatabase.sqlite';
if (file_exists($dbFileName))
$db = connect_to_db('hurrian_lexical_database');
$sql = <<<SQL
SELECT w.transcription, w.segmentation, l.translation_de, s.morph_tag, l.part_of_speech, l.determinative
FROM wordform w
INNER JOIN lemma l ON l.lemma_id = w.lemma_id
INNER JOIN suffix_chain s ON s.suffix_chain_id = w.suffix_chain_id;
SQL;
$result = $db->query($sql);
$data = array();
while ($row = $result->fetch_assoc())
{
$db = new SQLite3($dbFileName);
$sql = <<<SQL
SELECT w.transcription, w.segmentation, l.translation_de, s.morph_tag, l.part_of_speech, l.det
FROM wordforms w
INNER JOIN lemmata l ON l.lemma_id = w.lemma_id
INNER JOIN suffix_chains s ON s.suffix_chain_id = w.suffix_chain_id;
SQL;
$result = $db->query($sql);
$data = array();
while ($row = $result->fetchArray())
{
$fields = array($row['segmentation'],
$row['translation_de'],
$row['morph_tag'],
$row['part_of_speech'],
$row['det']);
$data[$row['transcription']][] = implode(' @ ', $fields);
}
echo json_encode($data, JSON_UNESCAPED_UNICODE);
}
else
{
echo '{}';
$fields = array($row['segmentation'],
$row['translation_de'],
$row['morph_tag'],
$row['part_of_speech'],
$row['determinative']);
$data[$row['transcription']][] = implode(' @ ', $fields);
}
echo json_encode($data, JSON_UNESCAPED_UNICODE);
?>
31 changes: 12 additions & 19 deletions html/hurrian/getHurrianLexicon.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
<?php
require_once '../mysqliconn.php';
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/json');
$dbFileName = 'hurrianLexicalDatabase.sqlite';
if (file_exists($dbFileName))
$db = connect_to_db('hurrian_lexical_database');
$sql = <<<SQL
SELECT stem, part_of_speech, translation_de
FROM lemma;
SQL;
$result = $db->query($sql);
$data = array();
while ($row = $result->fetch_assoc())
{
$db = new SQLite3($dbFileName);
$sql = <<<SQL
SELECT stem, part_of_speech, translation_de
FROM lemmata;
SQL;
$result = $db->query($sql);
$data = array();
while ($row = $result->fetchArray())
{
$key = $row['stem'].','.$row['part_of_speech'];
$data[$key][] = $row['translation_de'];
}
echo json_encode($data, JSON_UNESCAPED_UNICODE);
}
else
{
echo '{}';
$key = $row['stem'].','.$row['part_of_speech'];
$data[$key][] = $row['translation_de'];
}
echo json_encode($data, JSON_UNESCAPED_UNICODE);
?>
69 changes: 21 additions & 48 deletions html/hurrian/updateHurrianDictionary.php
Original file line number Diff line number Diff line change
@@ -1,102 +1,75 @@
<?php
require_once '../mysqliconn.php';
header('Access-Control-Allow-Origin: *');
include('commonHurrian.php');
$dbFileName = 'hurrianLexicalDatabase.sqlite';
$dbExists = file_exists($dbFileName);
$word = $_POST['word'];
$analysis = $_POST['analysis'];
list($segmentation, $translation, $tag, $template, $det) = explode(' @ ', $analysis);
$pos = getPos($template);
list($stem, $suffixes) = parseSegmentation($segmentation);

//Datenbank öffnen oder erstellen
$db = new SQLite3($dbFileName);
if (!$dbExists)
{
$sql = <<<SQL
CREATE TABLE 'lemmata' (
'lemma_id' INTEGER PRIMARY KEY,
'stem' TEXT,
'part_of_speech' TEXT,
'translation_de' TEXT,
'det' TEXT
);
CREATE TABLE 'suffix_chains' (
'suffix_chain_id' INTEGER PRIMARY KEY,
'suffixes' TEXT,
'morph_tag' TEXT,
'part_of_speech' TEXT
);
CREATE TABLE 'wordforms' (
'wordform_id' INTEGER PRIMARY KEY,
'transcription' TEXT,
'segmentation' TEXT,
'lemma_id' INTEGER,
'suffix_chain_id' INTEGER
);
SQL;
$db->exec($sql);
}
//Datenbank öffnen
$db = connect_to_db('hurrian_lexical_database');

//Lemma finden oder hinzufügen
$findLemma = <<<SQL
SELECT lemma_id
FROM 'lemmata'
FROM lemma
WHERE stem = '$stem'
AND part_of_speech = '$pos'
AND translation_de = '$translation'
AND det = '$det';
AND determinative = '$det';
SQL;
$result = $db->query($findLemma);
$row = $result->fetchArray();
$row = $result->fetch_assoc();
if (!$row) {
$sql = <<<SQL
INSERT INTO 'lemmata' ('stem', 'part_of_speech', 'translation_de', 'det')
VALUES ('$stem', '$pos', '$translation', '$det');
INSERT INTO lemma (lemma_id, stem, part_of_speech, translation_de, determinative)
VALUES (null, '$stem', '$pos', '$translation', '$det');
SQL;
$db->exec($sql);
$db->query($sql);
$result = $db->query($findLemma);
$row = $result->fetchArray();
$row = $result->fetch_assoc();
}
$lemma_id = $row['lemma_id'];

//Suffixkette finden oder hinzufügen
$findSuffixChain = <<<SQL
SELECT suffix_chain_id
FROM 'suffix_chains'
FROM suffix_chain
WHERE suffixes = '$suffixes'
AND morph_tag = '$tag'
AND part_of_speech = '$pos';
SQL;
$result = $db->query($findSuffixChain);
$row = $result->fetchArray();
$row = $result->fetch_assoc();
if (!$row) {
$sql = <<<SQL
INSERT INTO 'suffix_chains' ('suffixes', 'morph_tag', 'part_of_speech')
VALUES ('$suffixes', '$tag', '$pos');
INSERT INTO suffix_chain (suffix_chain_id, suffixes, morph_tag, part_of_speech)
VALUES (null, '$suffixes', '$tag', '$pos');
SQL;
$db->exec($sql);
$db->query($sql);
$result = $db->query($findSuffixChain);
$row = $result->fetchArray();
$row = $result->fetch_assoc();
}
$suffix_chain_id = $row['suffix_chain_id'];

//Wortform finden oder hinzufügen
$findWordform = <<<SQL
SELECT wordform_id
FROM 'wordforms'
FROM wordform
WHERE transcription = '$word'
AND segmentation = '$segmentation'
AND lemma_id = '$lemma_id'
AND suffix_chain_id = '$suffix_chain_id';
SQL;
$result = $db->query($findWordform);
$row = $result->fetchArray();
$row = $result->fetch_assoc();
if (!$row) {
$sql = <<<SQL
INSERT INTO 'wordforms' ('transcription', 'segmentation', 'lemma_id', 'suffix_chain_id')
VALUES ('$word', '$segmentation', '$lemma_id', '$suffix_chain_id')
INSERT INTO wordform (wordform_id, transcription, segmentation, lemma_id, suffix_chain_id)
VALUES (null, '$word', '$segmentation', '$lemma_id', '$suffix_chain_id')
SQL;
$db->exec($sql);
$db->query($sql);
}
?>
4 changes: 2 additions & 2 deletions html/mysqliconn.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
const database = 'hpm';
const port = 3406;

function connect_to_db(): mysqli
function connect_to_db($database=database): mysqli
{
$db = mysqli_connect(host, user, password, database, port);
$db = mysqli_connect(host, user, password, $database, port);

if ($db) {
return $db;
Expand Down
11 changes: 6 additions & 5 deletions sql_inits/00_users_init.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
create user hpm@'%' identified by '1234';

grant all on hpm.* to hpm@'%';

flush privileges;
create user hpm@'%' identified by '1234';

grant all on hpm.* to hpm@'%';
grant all on hurrian_lexical_database.* to hpm@'%';

flush privileges;
63 changes: 63 additions & 0 deletions sql_inits/create_hur_lex_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
create database if not exists hurrian_lexical_database;
use hurrian_lexical_database;

/*drop table if exists
wordform,
lemma,
suffix_chain;*/

/* begin table creation */

CREATE TABLE if not exists lemma (
lemma_id mediumint unsigned not null auto_increment,
stem text not null,
part_of_speech text not null,
translation_de text not null,
determinative text not null,
constraint pk_lemma primary key (lemma_id)
);

CREATE TABLE if not exists suffix_chain (
suffix_chain_id mediumint unsigned not null auto_increment,
suffixes text not null,
morph_tag text not null,
part_of_speech text not null,
constraint pk_suffix_chain primary key (suffix_chain_id)
);

CREATE TABLE if not exists wordform (
wordform_id mediumint unsigned not null auto_increment,
transcription text not null,
segmentation text not null,
lemma_id mediumint unsigned not null,
suffix_chain_id mediumint unsigned not null,
constraint fk_lemma_id foreign key (lemma_id)
references lemma (lemma_id),
constraint fk_suffix_chain_id foreign key (suffix_chain_id)
references suffix_chain (suffix_chain_id),
constraint pk_wordform primary key (wordform_id)
);

/* end table creation */

/* begin data population */

/* lemma data */
insert into lemma (lemma_id, stem, part_of_speech, translation_de, determinative)
values (null, 'nāli', 'noun', 'Rehbock', '');
insert into lemma (lemma_id, stem, part_of_speech, translation_de, determinative)
values (null, 'tāri', 'noun', 'Feuer', '');
insert into lemma (lemma_id, stem, part_of_speech, translation_de, determinative)
values (null, 'id', 'verb', 'schlagen', '');
insert into lemma (lemma_id, stem, part_of_speech, translation_de, determinative)
values (null, 'am', 'verb', 'brennen', '');

/* suffix chain data */
insert into suffix_chain (suffix_chain_id, suffixes, morph_tag, part_of_speech)
values (null, '(n>)re-ž', 'RELAT.SG-ERG', 'noun');

/* wordform data */
insert into wordform (wordform_id, transcription, segmentation, lemma_id, suffix_chain_id)
values (null, 'tārrež', 'tār(i)-(n>)re-ž', 2, 1);

/* end data population */
5 changes: 5 additions & 0 deletions sql_inits/query_hurrian_wordforms.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
select lemma.stem, /*transcription,*/ segmentation, lemma.translation_de, suffix_chain.morph_tag
from wordform
inner join lemma on wordform.lemma_id=lemma.lemma_id
inner join suffix_chain on wordform.suffix_chain_id=suffix_chain.suffix_chain_id
order by lemma.stem, transcription;
41 changes: 22 additions & 19 deletions ui/src/xmlEditor/hur/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { makeStandardAnalyses } from './standardAnalysis';
import { setGlosses, saveGloss } from './glossUpdater';
import { MorphologicalAnalysis, writeMorphAnalysisValue }
from '../../model/morphologicalAnalysis';
import { getHurrianDictionaryUrl } from '../../urls';
import { convertDictionary, updateAndValidateDictionary } from './utility';
import { isValid, normalize } from './morphologicalAnalysisValidator';
import { sendMorphologicalAnalysisToTheServer } from './sendToTheServer';

const dictionary: Map<string, Set<string>> = new Map();

Expand Down Expand Up @@ -80,25 +82,26 @@ export function sendMorphologicalAnalysisToTheServer(word: string, analysis: str
}

export function updateHurrianDictionary(node: XmlElementNode, number: number, value: string): void {
if (!isValid(value)) {
return;
}
value = normalize(value, false);
if (number === 1) {
delete node.attributes.firstAnalysisIsPlaceholder;
}
const transcription: string = node.attributes.trans || '';
let possibilities: Set<string> | undefined;
if (dictionary.has(transcription)) {
possibilities = dictionary.get(transcription);
}
else {
possibilities = new Set<string>();
dictionary.set(transcription, possibilities);
}
if (possibilities === undefined) {
throw new Error();

if (isValid(value)) {
value = normalize(value, false);
if (number === 1) {
delete node.attributes.firstAnalysisIsPlaceholder;
}
const transcription: string = node.attributes.trans || '';
let possibilities: Set<string> | undefined;
if (dictionary.has(transcription)) {
possibilities = dictionary.get(transcription);
}
else {
possibilities = new Set<string>();
dictionary.set(transcription, possibilities);
}
if (possibilities === undefined) {
throw new Error();
}
possibilities.add(value);
sendMorphologicalAnalysisToTheServer(transcription, value);
saveGloss(number, value);
}
}

Expand Down
9 changes: 9 additions & 0 deletions ui/src/xmlEditor/hur/sendToTheServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { updateHurrianDictionaryUrl } from '../../urls';

export function sendMorphologicalAnalysisToTheServer(word: string, analysis: string) {
const formData = new FormData();
formData.append('word', word);
formData.append('analysis', analysis);

fetch(updateHurrianDictionaryUrl, {method: 'POST', body: formData});
}
Loading