This commit is contained in:
倪 李俊 2017-03-18 15:46:20 +08:00
parent 266a2ebe21
commit ce773a97fa
4 changed files with 177 additions and 0 deletions

View File

@ -0,0 +1,106 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hebrew Strong Dictionary</title>
<script src="//cdn.bootcss.com/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
var dict={};
var dict_mapping={};
$(document).ready(()=>{
$.ajax({
url:'./json/StrongHebrewDictionary.json',
method:'get',
dataType:'json'
}).done((book)=>{
dict=book.dict;
dict_mapping=book.mapping;
}).fail(()=>{
alert('ajax failed');
})
});
function query_hebrew(){
let heb=$("#heb").val();
display_strong(dict_mapping[heb]);
}
function query_strong(){
let strong_number=$("#strong_number").val();
display_strong("H"+strong_number);
}
function display_strong(number){
let result="Not found.";
if(dict[number]){
let item=dict[number];
console.log(number,item);
result="";
result+="<h3>#"+number+" "+item.w.w+"</h3>";
result+="<p><span class='part_tag'>pos</span>"+item.w.pos+"</p>";
result+="<p><span class='part_tag'>pron</span>"+item.w.pron+"</p>";
result+="<p><span class='part_tag'>src</span>"+item.w.src+"</p>";
result+="<p><span class='part_tag'>xlit</span>"+item.w.xlit+"</p>";
result+="<p><span class='part_tag'>source</span>"+item.source+"</p>";
result+="<p><span class='part_tag'>meaning</span>"+item.meaning+"</p>";
result+="<p><span class='part_tag'>usage</span>"+item.usage+"</p>";
if(item.note){
result+="<p><span class='part_tag'>note</span>"+item.note+"</p>";
}
}
$("#resule_box").html(result);
}
</script>
<style type="text/css">
h3 {
}
p {
}
span.part_tag{
color: blue;
margin: auto 5px;
}
def {
color: green;
}
w {
color: red;
}
#query_box {
border-bottom: 1px solid gray;
margin: 10px;
}
#resule_box{
margin: 10px;
border-bottom: 1px solid gray;
min-height: 200px;
}
#footer {
text-align: center;
}
</style>
</head>
<body>
<h1>Hebrew Strong Dictionary</h1>
<div id="query_box">
<p>
Hebrew:
<input type="text" id="heb">
<button onclick="query_hebrew()">Query</button>
</p>
<p>
Strong Number:
<input type="text" id="strong_number">
<button onclick="query_strong()">Query</button>
</p>
</div>
<div id="resule_box">
</div>
<div id="footer">
Copyright 2017 Sinri Edogawa. Dictionary data powered by <a href="https://github.com/openscriptures/HebrewLexicon">Project HebrewLexicon</a>.
</div>
</body>
</html>
<!-- http://localhost/leqee/Lab/SinriStrongDict/HebrewStrongDictionary.html -->

9
sinri/README.md Normal file
View File

@ -0,0 +1,9 @@
# JSONify!
provide tools to turn the Strong's Hebrew XML data into json, and provide a html sample to use as a live dictionay.
> By Sinri Edogawa, 2017 March 18th
> For attribution purposes, the XML building project is https://github.com/openscriptures/HebrewLexicon.
> These files are released under the Creative Commons Attribution 4.0 International(http://creativecommons.org/licenses/by/4.0/) license.The actual text of Brown, Driver, Briggs and Strongs Hebrew dictionary remain in the public domain. For attribution purposes, credit the Open Scriptures Hebrew Bible Project.

61
sinri/StrongXML2Json.php Normal file
View File

@ -0,0 +1,61 @@
<?php
$xml_file_path=__DIR__.'/../HebrewStrong.xml';
$xsd_file_path=__DIR__.'/../StrongSchema.xml';
$json_file_path=__DIR__.'/json/StrongHebrewDictionary.json';
$xmlstr=file_get_contents($xml_file_path);
$lexicon = new SimpleXMLElement($xmlstr);
$dictionary=[];
$dictionary_mapping=[];
$debug_limit=10;
foreach ($lexicon as $entry) {
// entry attribute
$entry_id=(String)$entry['id'];
// property
// 1. <w pos="n-m" pron="awb" xlit="ʼâb" xml:lang="heb">אָב</w>
$w=[
"pos"=>(String)$entry->w['pos'],
"pron"=>(String)$entry->w['pron'],
"xlit"=>(String)$entry->w['xlit'],
"src"=>(String)$entry->w['src'],
"w"=>(String)$entry->w,
];
// 2. <source>a primitive word;</source>
$source=$entry->source->asXML();
// 3. <meaning><def>father</def>, in a literal and immediate, or figurative and remote application</meaning>
$meaning=$entry->meaning->asXML();
// 4. <usage>chief, (fore-) father(-less), × patrimony, principal. Compare names in 'Abi-'.</usage>
$usage=$entry->usage->asXML();
// 5. optional <note>xlit ʼĂbîyshûwac corrected to ʼĂbîyshûwaʻ</note>
$note=$entry->note->asXML();
$dictionary[$entry_id]=[
"w"=>$w,
"source"=>makeFalseAsEmptyString($source),
"meaning"=>makeFalseAsEmptyString($meaning),
"usage"=>makeFalseAsEmptyString($usage),
"note"=>makeFalseAsEmptyString($note),
];
$dictionary_mapping[$w['w']]=$entry_id;
// echo $entry_id." Done. ";
// if($debug_limit--<0)break;
}
echo PHP_EOL;
// print_r($dictionary);
// print_r($dictionary_mapping);
$strong_book = ["dict"=>$dictionary,"mapping"=>$dictionary_mapping];
$text=json_encode($strong_book);
if(file_exists($json_file_path)){
unlink($json_file_path);
}
$bytes=file_put_contents($json_file_path, $text);
echo "Byte/{$bytes} written to {$json_file_path}!".PHP_EOL;
function makeFalseAsEmptyString($x){
if(empty($x))$x="";
return $x;
}

File diff suppressed because one or more lines are too long