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
52 changes: 52 additions & 0 deletions html/hurrian/commonHurrian.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
function getPos($template)
{
if ($template === 'noun' || $template === 'indecl')
{
return $template;
}
else
{
return 'verb';
}
}
function findBoundary($word)
{
for ($i = 0; $i < strlen($word); $i++)
{
$char = $word[$i];
if ($char === '-' || $char === '=' || $char === '.')
{
return $i;
}
}
return -1;
}
$auxiliary = array('(', ')');
function normalizeStem($stem)
{
global $auxiliary;
$stem = str_replace($auxiliary, '', $stem);
return $stem;
}
function parseSegmentation($analysis)
{
$index = findBoundary($analysis);
if ($index !== -1)
{
$stem = substr($analysis, 0, $index);
if ($analysis[$index] === '-')
{
$index++;
}
$suffixChain = substr($analysis, $index);
}
else
{
$stem = $analysis;
$suffixChain = '';
}
$stem = normalizeStem($stem);
return array($stem, $suffixChain);
}
?>
31 changes: 31 additions & 0 deletions html/hurrian/getHurrianDictionary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/json');
$dbFileName = 'hurrianLexicalDatabase.sqlite';
if (file_exists($dbFileName))
{
$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 '{}';
}
?>
25 changes: 25 additions & 0 deletions html/hurrian/getHurrianLexicon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/json');
$dbFileName = 'hurrianLexicalDatabase.sqlite';
if (file_exists($dbFileName))
{
$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 '{}';
}
?>
Binary file added html/hurrian/hurrianLexicalDatabase.sqlite
Binary file not shown.
102 changes: 102 additions & 0 deletions html/hurrian/updateHurrianDictionary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?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);
}

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

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

//Wortform finden oder hinzufügen
$findWordform = <<<SQL
SELECT wordform_id
FROM 'wordforms'
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();
if (!$row) {
$sql = <<<SQL
INSERT INTO 'wordforms' ('transcription', 'segmentation', 'lemma_id', 'suffix_chain_id')
VALUES ('$word', '$segmentation', '$lemma_id', '$suffix_chain_id')
SQL;
$db->exec($sql);
}
?>
4 changes: 4 additions & 0 deletions ui/src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const baseUrl = process.env.NODE_ENV !== 'development'

export const apolloUri = `${baseServerUrl}/graphql.php`;

export const updateHurrianDictionaryUrl = baseServerUrl + '/hurrian/updateHurrianDictionary.php';
export const getHurrianDictionaryUrl = baseServerUrl + '/hurrian/getHurrianDictionary.php';
export const getHurrianLexiconUrl = baseServerUrl + '/hurrian/getHurrianLexicon.php';

export const pictureUploadUrl = (mainIdentifier: string): string => `${baseServerUrl}/uploadPicture.php?id=${encodeURIComponent(mainIdentifier)}`;

export const pictureBaseUrl = (mainIdentifier: string): string => `${baseServerUrl}/uploads/${encodeURIComponent(mainIdentifier)}`;
Expand Down
17 changes: 15 additions & 2 deletions ui/src/xmlEditor/hur/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { isValid, normalize } from './morphologicalAnalysisValidator';

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

fetch(getHurrianDictionaryUrl, {method: 'GET'}).then(response => {
response.json().then(obj => {
upgradeDictionary(obj);
});
});

export function annotateHurrianWord(node: XmlElementNode): void {
const transliteration: string = getText(node);
const transcription: string = makeBoundTranscription(transliteration);
Expand Down Expand Up @@ -65,6 +71,14 @@ export function annotateHurrianWord(node: XmlElementNode): void {
}
}

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});
}

export function updateHurrianDictionary(node: XmlElementNode, number: number, value: string): void {
if (!isValid(value)) {
return;
Expand All @@ -84,9 +98,8 @@ export function updateHurrianDictionary(node: XmlElementNode, number: number, va
}
if (possibilities === undefined) {
throw new Error();

}
possibilities.add(value);
saveGloss(number, value);
}

export function getDictionary(): { [key: string]: string[] } {
Expand Down
16 changes: 14 additions & 2 deletions ui/src/xmlEditor/hur/glossProvider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { getHurrianLexiconUrl } from '../../urls';
import {convertDictionary, updateGlossesLexicon} from './utility';

//Dieses Modul kann Bedeutungen von Stämmen speichern und nachschlagen.
const glosses: Map<string, Set<string>> = new Map();

function getKey(word: string, pos: string): string
fetch(getHurrianLexiconUrl, {method: 'GET'}).then(response => {
response.json().then(obj => {
upgradeGlosses(obj);
});
});

function preprocessStem(stem: string): string
{
return stem.replace('(', '').replace(')', '');
}

function getKey(stem: string, pos: string): string
{
return word + ',' + pos;
return preprocessStem(stem) + ',' + pos;
}

export function storeGloss(word: string, pos: string, gloss: string)
Expand Down
10 changes: 9 additions & 1 deletion ui/src/xmlEditor/hur/standardAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { MorphologicalAnalysis } from '../../model/morphologicalAnalysis';
import { SelectableLetteredAnalysisOption } from '../../model/analysisOptions';
import { getGrammaticalMorphemes } from './splitter';

function postprocessSegmentation(segmentation: string): string {
if (segmentation.endsWith('-')) {
segmentation = segmentation.substring(0, segmentation.length - 1);
}
return segmentation;
}

// Erstellt morphologische Analysen für Wörter, die im Lexicon fehlen.
// Das unbekannte Wort wird zuerst durch die Funktion "segment" in Morpheme getrennt, möglicherweise auf mehrere verschiedene Weisen.
// Der grammatische Teil der Segmentierung, die Suffixe und Enklitika, werden dann durch "analyze" grammatisch analysiert. Auch hier mehrere Optionen möglich.
Expand All @@ -13,7 +20,8 @@ export function makeStandardAnalyses(transcription: string): MorphologicalAnalys
const segmentations: [string, string][] = segment(transcription);

for (let i = 0; i < segmentations.length; i++) {
const [segmentation, pos] = segmentations[i];
const [initialSegmentation, pos] = segmentations[i];
const segmentation = postprocessSegmentation(initialSegmentation);
let ma: MorphologicalAnalysis;
const grammaticalMorphemes = getGrammaticalMorphemes(segmentation);
const tags: string[] | null = analyze(grammaticalMorphemes, pos);
Expand Down