<commit_before>---
layout: page 
title: From XML to RDF Step by Step
dropdown: FREME-Showroom
pos: 2.4
---

    <script type="text/javascript" src="../js/jquery-ui-1.11.4/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../js/Saxon-CE_1.1/Saxonce/Saxonce.nocache.js"></script>
    <script>
            function xsltTransform(xslSourcePath, xmlString, params) {
                console.log("xsl in path: " + xslSourcePath);
                var proc = Saxon.newXSLT20Processor();
		if(params){
		$.each(params, function(index, item) {
		   console.log("ns:" + item.ns + "name:" + item.name);
		   proc.setParameter(item.ns, item.name, item.value);
		});};
                var xslSource = Saxon.requestXML(xslSourcePath);
                var xmlSource = Saxon.parseXML(xmlString);
                proc.importStylesheet(xslSource);
                var fragment = proc.transformToFragment(xmlSource, document);
                console.log("transformed version:" + Saxon.serializeXML(fragment));
                return Saxon.serializeXML(fragment);
            }
            ;
            var sendFreme = function () {
            	var libPath = "xml-to-rdf/lib";
		var xslSourcePath = "";
		//var params = [{ "ns" : null, "name" : "tbd", "value" : "tbd"}]; 
                var selectedLanguage = $("#language").find(":selected").val();
                var selectedDataset = $("#dataset").find(":selected").val();
                var doctype = $("#doctype").find(":selected").val();
		 switch (doctype) {
                    case "1" :
                        xslSourcePath = libPath+"/tei-processing/tei2temp-html.xsl";
                        break;
                    case "2" :
                        xslSourcePath = libPath+"/docbook-processing/docbook2temp-html.xsl";
                }
                ;
                var approach = $('#approach').find(":selected").val();
		var sourceContent = $('#content').val();
                var stylesheetchoice = "doctype:" + doctype + "approach:" + approach;
                console.log("approach:" + approach);
                console.log("doctype: " + doctype);
                console.log("language: " + selectedLanguage);
                console.log("dataset: " + selectedDataset);
                var requestBody = xsltTransform(xslSourcePath,sourceContent);
                var requestURL = fremeApiUrl + "/e-entity/freme-ner/documents?language=" + selectedLanguage + "&dataset=" + selectedDataset;
                if (approach === "2" || approach === "3" || approach === "5") {
                    $.ajax({
                        type: 'POST',
                        url: requestURL,
                        data: requestBody,
                        headers: {                            'Accept': 'text/html',
                            'Content-Type': 'text/html'
                        }
                    })
                            .done(function (result1) {
                                //console.log("success" + result1.toString());
                                $("#out").empty().append(result1);
                                console.log("transform back start");
                                console.log("stylesheetchoice: " + stylesheetchoice);
                                switch (stylesheetchoice) {
                                    case "doctype:1approach:2" :
                                        xslSourcePath = libPath+"/tei-processing/temp2tei-approach-2.xsl";
                                        break;
                                    case "doctype:1approach:3" :
                                        xslSourcePath = libPath+"/tei-processing/temp2tei-approach-3.xsl";
                                        break;
                                    case "doctype:2approach:2" :
                                        xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-2.xsl";
                                        break;
                                    case "doctype:2approach:3" :
                                        xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-3.xsl";
                                        break;
                                    case "doctype:1approach:5" :
                                        xslSourcePath = libPath+"/tei-processing/temp2tei-approach-2.xsl";
                                        break;
                                    case "doctype:2approach:5" :
                                        xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-2.xsl";
                                }
                                ;
                                console.log("approach 2,3,5 path" + xslSourcePath);
				var tempstring = xsltTransform(xslSourcePath, sourceContent, []);
                                console.log("approach:" + approach);
                                if (approach === "2" || approach === "3") {
                                    var tempstring2 = tempstring.replace(/</g, "&lt;");
                                    $("#output2").empty().append(tempstring2);
                                } else if (approach === "5") {
                                    console.log("running approach 5");
                                    $("#output2").empty();
                                    switch (stylesheetchoice) {
                                        case "doctype:1approach:5" :
                                            xslSourcePath = libPath+"/tei-processing/temp2tei-approach-5.xsl";
                                            break;
                                        case "doctype:2approach:5" :
                                            xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-5.xsl";
                                    }
                                    console.log("approach 5 path:" + xslSourcePath);
				    var tempstring5 = xsltTransform(xslSourcePath, tempstring, []);
                                    var tempstring52 = tempstring5.replace(/</g, "&lt;");
                                    $("#output2").empty().append(tempstring52);
                                }
                            })
                            .fail(function (data) {
                                console.log("error");
                                error(data);
                                $("#out").empty().append("Search request failed");
                            });
                } else {
                    $.ajax({
                        type: 'POST',
                        url: requestURL,
                        data: sourceContent,
                        headers: {
                            'Accept': 'text/turtle',
                            'Content-Type': 'text/html'
                        }
                    })
                            .done(function (result1) {
                                var tempstring2 = result1.replace(/</g, "&lt;");
                                if (approach === "1") {
                                    $("#output2").empty().append(tempstring2);
                                } else if (approach === "4") {
                                    //console.log("approach 4 output" +  tempstring2);
                                    $("#out").empty().append(tempstring2);
                                    switch (stylesheetchoice) {
                                        case "doctype:1approach:4" :
                                            xslSourcePath = libPath+"/tei-processing/temp2tei-approach-4.xsl";
                                            break;
                                        case "doctype:2approach:4" :
                                            xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-4.xsl";
                                    }
                                    ;
                                    console.log("xsl source for approach 4: " + xslSourcePath);
				    var tempstring = xsltTransform(xslSourcePath, sourceContent, [{"ns" : null, "name" : "rdfoutput", "value" : tempstring2}]);
                                    var tempstring2 = tempstring.replace(/</g, "&lt;");
                                    $("#output2").empty().append(tempstring2);
                                }
                                ;
                            })
                            .fail(function (data) {
                                console.log("error");
                                error(data);
                                $("#out").empty().append("Search request failed");
                            });
                }
                ;
                ;
            };
	</script>
	
	<style>
	    textarea.input { color: green;
			     float: left;
			     width: 45%;
			     margin-left: 10px;
			     margin-top: 10px;
			     padding: 5px;
			     border: 1px solid black;
	    }
	    textarea.output { color: blue;
			      float: right;
			      width: 45%;
			      margin-right: 10px;
			      margin-top: 10px;
			      padding: 5px;
			      border: 1px solid black;
	    }
	    span.loadsample {
		color: blue;
	    }
	</style>
	
	<h1>From XML to RDF Step by Step</h1>
	<h2 id="background">Background</h2>
	<p>This examples shows how to process XML content with FREME. For background to the XML and RDF processing options, see the related <a href="http://fsasaki.github.io/stuff/xmlprague2016/sasaki-et-al-xmlprague-2016.html">XML Prague 2016 paper</a>.</p>
	<h2 id="more-infos">More information</h2>
	<p>For more information visit the <a target="_blank" href="{{ site.baseurl | prepend: site.url }}/api-doc/fulxxxl.html">FREME API documentation</a>, <a target="_blank" href="https://github.com/freme-project/">FREME on GitHub</a> or the <a target="_blank" href="http://freme-project.eu/">FREME homepage</a>.</p>
	<h2 id="try-it-out">Try it out</h2>
	<p>In the left form below enter a Docbook 5.0 (<span class="loadsample" onclick="var docbooksample = $('#docbooksample').text();
                $('#content').empty().val(docbooksample.replace(/</g, '&lt;'))">load a sample</span>) document or TEI P5 document (<span class="loadsample" onclick="var teisample = $('#teisample').text();
                $('#content').empty().val(teisample.replace(/</g, '&lt;'))">load a sample</span>) and click on the bottom <q>Call FREME e-Entity</q>. Also, adapt the language and the data set used for enrichment to your needs.</p>
	<button onclick="sendFreme();">Call FREME e-Entity with XML content</button>
	<button onclick="$('#out').empty().append('Output');
                $('#output2').empty();">Refresh output</button>
	<form name="input">
	    <p>Set the document type of the input: <select name="doctype" id="doctype"><option value="1">TEI</option><option value="2" selected>DocBook</option></select></p>
	    <p>Set the language of the input: <select name="language" id="language"><option value="en" selected>English</option><option value="de">German</option><option value="nl">Dutch</option><option value="fr">French</option><option value="it">Italien</option><option value="es">Spanish</option></select></p>
	    <p>Set the data set to be used for enrichment: <select name="dataset" id="dataset"><option value="dbpedia" selected>DBpedia</option><option value="onld">ONLD</option><option value="geopolitical">Geopolitical ontology</option><option value="viaf">VIAF</option><option value="orcid">ORCID</option></select></p>
	    <p>Set the output type: <select name="approach" id="approach"><option value="1">1. Convert XML to linked data</option><option value="2">2. Embedd Linked Data into XML via Structured Markup</option><option value="3">3. Anchor Linked Data in XML Attributes</option><option value="4">4. Embed Linked Data in Metadata Sections of XML Files</option><option value="5">5. Anchor Linked Data via Annotations in XML Content</option></select></p>
	    <textarea rows="15" cols="50" name="content"  id="content" class="input"></textarea>
	</form>
	<div id="out" style="display: none;">Output</div>
	<form name="output">
	    <textarea rows="15" cols="50" name="output2"  id="output2" class="output"></textarea>
	</form>
	<div id="docbooksample" style="display: none;">
&lt;article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"><commit_msg>Update xml-to-rdf.html<commit_after>---
layout: page 
title: From XML to RDF Step by Step
dropdown: FREME-Showroom
pos: 2.4
---

    <script type="text/javascript" src="../js/jquery-ui-1.11.4/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../js/Saxon-CE_1.1/Saxonce/Saxonce.nocache.js"></script>
    <script>
            function xsltTransform(xslSourcePath, xmlString, params) {
                console.log("xsl in path: " + xslSourcePath);
                var proc = Saxon.newXSLT20Processor();
		if(params){
		$.each(params, function(index, item) {
		   console.log("ns:" + item.ns + "name:" + item.name);
		   proc.setParameter(item.ns, item.name, item.value);
		});};
                var xslSource = Saxon.requestXML(xslSourcePath);
                var xmlSource = Saxon.parseXML(xmlString);
                proc.importStylesheet(xslSource);
                var fragment = proc.transformToFragment(xmlSource, document);
                console.log("transformed version:" + Saxon.serializeXML(fragment));
                return Saxon.serializeXML(fragment);
            }
            ;
            var sendFreme = function () {
            	var libPath = "xml-to-rdf/lib";
		var xslSourcePath = "";
		//var params = [{ "ns" : null, "name" : "tbd", "value" : "tbd"}]; 
                var selectedLanguage = $("#language").find(":selected").val();
                var selectedDataset = $("#dataset").find(":selected").val();
                var doctype = $("#doctype").find(":selected").val();
		 switch (doctype) {
                    case "1" :
                        xslSourcePath = libPath+"/tei-processing/tei2temp-html.xsl";
                        break;
                    case "2" :
                        xslSourcePath = libPath+"/docbook-processing/docbook2temp-html.xsl";
                }
                ;
                var approach = $('#approach').find(":selected").val();
		var sourceContent = $('#content').val();
                var stylesheetchoice = "doctype:" + doctype + "approach:" + approach;
                console.log("approach:" + approach);
                console.log("doctype: " + doctype);
                console.log("language: " + selectedLanguage);
                console.log("dataset: " + selectedDataset);
                var requestBody = xsltTransform(xslSourcePath,sourceContent);
                var requestURL = fremeApiUrl + "/e-entity/freme-ner/documents?language=" + selectedLanguage + "&dataset=" + selectedDataset;
                if (approach === "2" || approach === "3" || approach === "5") {
                    $.ajax({
                        type: 'POST',
                        url: requestURL,
                        data: requestBody,
                        headers: {                            'Accept': 'text/html',
                            'Content-Type': 'text/html'
                        }
                    })
                            .done(function (result1) {
                                //console.log("success" + result1.toString());
                                $("#out").empty().append(result1);
                                console.log("transform back start");
                                console.log("stylesheetchoice: " + stylesheetchoice);
                                switch (stylesheetchoice) {
                                    case "doctype:1approach:2" :
                                        xslSourcePath = libPath+"/tei-processing/temp2tei-approach-2.xsl";
                                        break;
                                    case "doctype:1approach:3" :
                                        xslSourcePath = libPath+"/tei-processing/temp2tei-approach-3.xsl";
                                        break;
                                    case "doctype:2approach:2" :
                                        xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-2.xsl";
                                        break;
                                    case "doctype:2approach:3" :
                                        xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-3.xsl";
                                        break;
                                    case "doctype:1approach:5" :
                                        xslSourcePath = libPath+"/tei-processing/temp2tei-approach-2.xsl";
                                        break;
                                    case "doctype:2approach:5" :
                                        xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-2.xsl";
                                }
                                ;
                                console.log("approach 2,3,5 path" + xslSourcePath);
				var tempstring = xsltTransform(xslSourcePath, sourceContent, []);
                                console.log("approach:" + approach);
                                if (approach === "2" || approach === "3") {
                                    var tempstring2 = tempstring.replace(/</g, "&lt;");
                                    $("#output2").empty().append(tempstring2);
                                } else if (approach === "5") {
                                    console.log("running approach 5");
                                    $("#output2").empty();
                                    switch (stylesheetchoice) {
                                        case "doctype:1approach:5" :
                                            xslSourcePath = libPath+"/tei-processing/temp2tei-approach-5.xsl";
                                            break;
                                        case "doctype:2approach:5" :
                                            xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-5.xsl";
                                    }
                                    console.log("approach 5 path:" + xslSourcePath);
				    var tempstring5 = xsltTransform(xslSourcePath, tempstring, []);
                                    var tempstring52 = tempstring5.replace(/</g, "&lt;");
                                    $("#output2").empty().append(tempstring52);
                                }
                            })
                            .fail(function (data) {
                                console.log("error");
                                error(data);
                                $("#out").empty().append("Search request failed");
                            });
                } else {
                    $.ajax({
                        type: 'POST',
                        url: requestURL,
                        data: sourceContent,
                        headers: {
                            'Accept': 'text/turtle',
                            'Content-Type': 'text/html'
                        }
                    })
                            .done(function (result1) {
                                var tempstring2 = result1.replace(/</g, "&lt;");
                                if (approach === "1") {
                                    $("#output2").empty().append(tempstring2);
                                } else if (approach === "4") {
                                    //console.log("approach 4 output" +  tempstring2);
                                    $("#out").empty().append(tempstring2);
                                    switch (stylesheetchoice) {
                                        case "doctype:1approach:4" :
                                            xslSourcePath = libPath+"/tei-processing/temp2tei-approach-4.xsl";
                                            break;
                                        case "doctype:2approach:4" :
                                            xslSourcePath = libPath+"/docbook-processing/temp2docbook-approach-4.xsl";
                                    }
                                    ;
                                    console.log("xsl source for approach 4: " + xslSourcePath);
				    var tempstring = xsltTransform(xslSourcePath, sourceContent, [{"ns" : null, "name" : "rdfoutput", "value" : tempstring2}]);
                                    var tempstring2 = tempstring.replace(/</g, "&lt;");
                                    $("#output2").empty().append(tempstring2);
                                }
                                ;
                            })
                            .fail(function (data) {
                                console.log("error");
                                error(data);
                                $("#out").empty().append("Search request failed");
                            });
                }
                ;
                ;
            };
	</script>
	
	<style>
	    textarea.input { color: green;
			     float: left;
			     width: 45%;
			     margin-left: 10px;
			     margin-top: 10px;
			     padding: 5px;
			     border: 1px solid black;
	    }
	    textarea.output { color: blue;
			      float: right;
			      width: 45%;
			      margin-right: 10px;
			      margin-top: 10px;
			      padding: 5px;
			      border: 1px solid black;
	    }
	    span.loadsample {
		color: blue;
	    }
	</style>
	
	<h1>From XML to RDF Step by Step</h1>
	<h2 id="background">Background</h2>
	<p>This examples shows how to process XML content with FREME. For background to the XML and RDF processing options, see the related <a href="http://fsasaki.github.io/stuff/xmlprague2016/sasaki-et-al-xmlprague-2016.html">XML Prague 2016 paper</a>.</p>
	<h2 id="more-infos">More information</h2>
	<p>For more information visit the <a target="_blank" href="{{ site.baseurl | prepend: site.url }}/api-doc/full.html">FREME API documentation</a>, <a target="_blank" href="https://github.com/freme-project/">FREME on GitHub</a> or the <a target="_blank" href="http://freme-project.eu/">FREME homepage</a>.</p>
	<h2 id="try-it-out">Try it out</h2>
	<p>In the left form below enter a Docbook 5.0 (<span class="loadsample" onclick="var docbooksample = $('#docbooksample').text();
                $('#content').empty().val(docbooksample.replace(/</g, '&lt;'))">load a sample</span>) document or TEI P5 document (<span class="loadsample" onclick="var teisample = $('#teisample').text();
                $('#content').empty().val(teisample.replace(/</g, '&lt;'))">load a sample</span>) and click on the bottom <q>Call FREME e-Entity</q>. Also, adapt the language and the data set used for enrichment to your needs.</p>
	<button onclick="sendFreme();">Call FREME e-Entity with XML content</button>
	<button onclick="$('#out').empty().append('Output');
                $('#output2').empty();">Refresh output</button>
	<form name="input">
	    <p>Set the document type of the input: <select name="doctype" id="doctype"><option value="1">TEI</option><option value="2" selected>DocBook</option></select></p>
	    <p>Set the language of the input: <select name="language" id="language"><option value="en" selected>English</option><option value="de">German</option><option value="nl">Dutch</option><option value="fr">French</option><option value="it">Italien</option><option value="es">Spanish</option></select></p>
	    <p>Set the data set to be used for enrichment: <select name="dataset" id="dataset"><option value="dbpedia" selected>DBpedia</option><option value="onld">ONLD</option><option value="geopolitical">Geopolitical ontology</option><option value="viaf">VIAF</option><option value="orcid">ORCID</option></select></p>
	    <p>Set the output type: <select name="approach" id="approach"><option value="1">1. Convert XML to linked data</option><option value="2">2. Embedd Linked Data into XML via Structured Markup</option><option value="3">3. Anchor Linked Data in XML Attributes</option><option value="4">4. Embed Linked Data in Metadata Sections of XML Files</option><option value="5">5. Anchor Linked Data via Annotations in XML Content</option></select></p>
	    <textarea rows="15" cols="50" name="content"  id="content" class="input"></textarea>
	</form>
	<div id="out" style="display: none;">Output</div>
	<form name="output">
	    <textarea rows="15" cols="50" name="output2"  id="output2" class="output"></textarea>
	</form>
	<div id="docbooksample" style="display: none;">
&lt;article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
{'fraction_non_alphanumeric': 0.13528653179656647, 'fraction_numerical': 0.01313774482147175, 'mean_word_length': 1.424523693209575, 'pattern_counts': {'":': 8, '<': 221, '<?xml version=': 0, '>': 211, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 19}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 132, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6943680', 'n_tokens_mistral': 6696, 'n_tokens_neox': 6139, 'n_words': 1230}