Initial checkin.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@1077 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
ae7a74b196
commit
dda1714d17
16
extensions/rdf-exporter/.classpath
Normal file
16
extensions/rdf-exporter/.classpath
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/gridworks"/>
|
||||||
|
<classpathentry kind="lib" path="/gridworks/webapp/WEB-INF/lib/json-20100208.jar" sourcepath="/gridworks/webapp/WEB-INF/lib-src/json-20100208-sources.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/gridworks-server/lib/servlet-api-2.5.jar" sourcepath="/gridworks-server/lib-src/servlet-api-2.5-sources.jar"/>
|
||||||
|
<classpathentry kind="lib" path="module/MOD-INF/lib/arq-2.7.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="module/MOD-INF/lib/arq-extra-2.7.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="module/MOD-INF/lib/iri-0.6.jar"/>
|
||||||
|
<classpathentry kind="lib" path="module/MOD-INF/lib/jena-2.6.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="module/MOD-INF/lib/lucene-core-3.0.1.jar"/>
|
||||||
|
<classpathentry kind="lib" path="module/MOD-INF/lib/xercesImpl-2.7.1.jar"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/gridworks-server"/>
|
||||||
|
<classpathentry kind="output" path="module/MOD-INF/classes"/>
|
||||||
|
</classpath>
|
17
extensions/rdf-exporter/.project
Normal file
17
extensions/rdf-exporter/.project
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>rdf-exporter</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
28
extensions/rdf-exporter/LICENSE.txt
Normal file
28
extensions/rdf-exporter/LICENSE.txt
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* External Licenses
|
||||||
|
*/
|
||||||
|
|
||||||
|
See the 'licenses' directory for a list of the licenses for the libraries we depend on,
|
||||||
|
ordered here by license:
|
||||||
|
|
||||||
|
Jena 2.6.0
|
||||||
|
(c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP
|
||||||
|
http://jena.sourceforge.net/license.html
|
||||||
|
|
||||||
|
ARQ, ARQ Extra 2.7.0
|
||||||
|
(c) Copyright 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP
|
||||||
|
(c) Copyright 2010 Talis Information Ltd
|
||||||
|
All rights reserved.
|
||||||
|
http://jena.sourceforge.net/ARQ/license.html
|
||||||
|
|
||||||
|
iri 0.6
|
||||||
|
(c) Copyright 2007 Hewlett-Packard Development Company, LP
|
||||||
|
http://jena.sourceforge.net/iri/license.html
|
||||||
|
|
||||||
|
Lucene 3.0.1
|
||||||
|
Apache License
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
|
||||||
|
xercesImpl 2.7.1
|
||||||
|
Apache License
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0.html
|
66
extensions/rdf-exporter/build.xml
Normal file
66
extensions/rdf-exporter/build.xml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--+
|
||||||
|
|
|
||||||
|
| Gridworks Extension RDF Exporter Build File
|
||||||
|
|
|
||||||
|
+-->
|
||||||
|
|
||||||
|
<project name="gridworks-rdf-exporter" default="build" basedir=".">
|
||||||
|
|
||||||
|
<property environment="env"/>
|
||||||
|
|
||||||
|
<condition property="version" value="trunk">
|
||||||
|
<not><isset property="version"/></not>
|
||||||
|
</condition>
|
||||||
|
|
||||||
|
<condition property="revision" value="rXXXX">
|
||||||
|
<not><isset property="revision"/></not>
|
||||||
|
</condition>
|
||||||
|
|
||||||
|
<condition property="full_version" value="0.0.0.0">
|
||||||
|
<not><isset property="full_version"/></not>
|
||||||
|
</condition>
|
||||||
|
|
||||||
|
<condition property="dist.dir" value="dist">
|
||||||
|
<not><isset property="dist.dir"/></not>
|
||||||
|
</condition>
|
||||||
|
|
||||||
|
<property name="fullname" value="${name}-${version}-${revision}" />
|
||||||
|
|
||||||
|
<property name="gridworks.dir" value="${basedir}/../../main" />
|
||||||
|
<property name="gridworks.webinf.dir" value="${gridworks.dir}/webapp/WEB-INF" />
|
||||||
|
<property name="gridworks.modinf.dir" value="${gridworks.dir}/webapp/modules/core/MOD-INF" />
|
||||||
|
<property name="gridworks.classes.dir" value="${gridworks.webinf.dir}/classes" />
|
||||||
|
<property name="gridworks.lib.dir" value="${gridworks.webinf.dir}/lib" />
|
||||||
|
|
||||||
|
<property name="src.dir" value="${basedir}/src" />
|
||||||
|
<property name="module.dir" value="${basedir}/module" />
|
||||||
|
<property name="modinf.dir" value="${module.dir}/MOD-INF" />
|
||||||
|
<property name="lib.dir" value="${modinf.dir}/lib" />
|
||||||
|
<property name="classes.dir" value="${modinf.dir}/classes" />
|
||||||
|
|
||||||
|
<path id="class.path">
|
||||||
|
<fileset dir="${lib.dir}">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
</fileset>
|
||||||
|
<fileset dir="${gridworks.lib.dir}">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
</fileset>
|
||||||
|
<pathelement path="${gridworks.classes.dir}"/>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<target name="build_java">
|
||||||
|
<mkdir dir="${classes.dir}" />
|
||||||
|
<javac destdir="${classes.dir}" debug="true" includeAntRuntime="no">
|
||||||
|
<src path="${src.dir}"/>
|
||||||
|
<classpath refid="class.path" />
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="build" depends="build_java"/>
|
||||||
|
|
||||||
|
<target name="clean">
|
||||||
|
<delete dir="${classes.dir}" />
|
||||||
|
</target>
|
||||||
|
</project>
|
29
extensions/rdf-exporter/licenses/arq.LICENSE.txt
Normal file
29
extensions/rdf-exporter/licenses/arq.LICENSE.txt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
ARQ 2.7.0
|
||||||
|
|
||||||
|
http://jena.sourceforge.net/ARQ/license.html
|
||||||
|
|
||||||
|
(c) Copyright 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP
|
||||||
|
(c) Copyright 2010 Talis Information Ltd
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
extensions/rdf-exporter/licenses/iri.LICENSE.txt
Normal file
30
extensions/rdf-exporter/licenses/iri.LICENSE.txt
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
iri 0.6
|
||||||
|
http://jena.sourceforge.net/iri/license.html
|
||||||
|
|
||||||
|
Copyright 2007 Hewlett-Packard Development Company, LP
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or
|
||||||
|
without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
29
extensions/rdf-exporter/licenses/jena.LICENSE.txt
Normal file
29
extensions/rdf-exporter/licenses/jena.LICENSE.txt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Jena 2.6.0
|
||||||
|
http://jena.sourceforge.net/license.html
|
||||||
|
|
||||||
|
(c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or
|
||||||
|
without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
77
extensions/rdf-exporter/module/MOD-INF/controller.js
Executable file
77
extensions/rdf-exporter/module/MOD-INF/controller.js
Executable file
@ -0,0 +1,77 @@
|
|||||||
|
|
||||||
|
importPackage(com.metaweb.gridworks.rdf.commands);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function invoked to initialize the extension.
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
/*
|
||||||
|
* Attach an rdf schema to each project.
|
||||||
|
*/
|
||||||
|
Packages.com.metaweb.gridworks.model.Project.registerOverlayModel(
|
||||||
|
"rdfSchema",
|
||||||
|
Packages.com.metaweb.gridworks.rdf.RdfSchema);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Operations
|
||||||
|
*/
|
||||||
|
Packages.com.metaweb.gridworks.operations.OperationRegistry.register(
|
||||||
|
"save-rdf-schema", Packages.com.metaweb.gridworks.rdf.operations.SaveRdfSchemaOperation);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Exporters
|
||||||
|
*/
|
||||||
|
var ExportRowsCommand = Packages.com.metaweb.gridworks.commands.project.ExportRowsCommand;
|
||||||
|
var RdfExporter = Packages.com.metaweb.gridworks.rdf.exporters.RdfExporter;
|
||||||
|
|
||||||
|
ExportRowsCommand.registerExporter("rdf", new RdfExporter("RDF/XML"));
|
||||||
|
ExportRowsCommand.registerExporter("n3", new RdfExporter("N3"));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GEL Functions and Binders
|
||||||
|
*/
|
||||||
|
Packages.com.metaweb.gridworks.gel.ControlFunctionRegistry.registerFunction(
|
||||||
|
"urlify", new Packages.com.metaweb.gridworks.rdf.expr.functions.strings.Urlify());
|
||||||
|
|
||||||
|
Packages.com.metaweb.gridworks.expr.ExpressionUtils.registerBinder(
|
||||||
|
new Packages.com.metaweb.gridworks.rdf.expr.RdfBinder());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Commands
|
||||||
|
*/
|
||||||
|
var GridworksServlet = Packages.com.metaweb.gridworks.GridworksServlet;
|
||||||
|
GridworksServlet.registerCommand("save-rdf-schema", new SaveRdfSchemaCommand());
|
||||||
|
GridworksServlet.registerCommand("preview-rdf",new PreviewRdfCommand());
|
||||||
|
GridworksServlet.registerCommand("save-baseURI",new SaveBaseURI());
|
||||||
|
GridworksServlet.registerCommand("suggest-term",new SuggestTermCommand());
|
||||||
|
GridworksServlet.registerCommand("import-vocabulary",new ImportVocabularyCommand());
|
||||||
|
GridworksServlet.registerCommand("list-vocabularies",new ListVocabulariesCommand());
|
||||||
|
GridworksServlet.registerCommand("delete-vocabulary",new DeleteVocabularyCommand());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Client-side Resources
|
||||||
|
*/
|
||||||
|
var ClientSideResourceManager = Packages.com.metaweb.gridworks.ClientSideResourceManager;
|
||||||
|
|
||||||
|
// Script files to inject into /project page
|
||||||
|
ClientSideResourceManager.addPaths(
|
||||||
|
"project/scripts",
|
||||||
|
module,
|
||||||
|
[
|
||||||
|
"scripts/menu-bar-extensions.js",
|
||||||
|
"scripts/rdf-schema-alignment.js",
|
||||||
|
"scripts/rdf-schema-alignment-ui-node.js",
|
||||||
|
"scripts/rdf-schema-alignment-ui-link.js",
|
||||||
|
"scripts/suggestterm.suggest.js"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Style files to inject into /project page
|
||||||
|
ClientSideResourceManager.addPaths(
|
||||||
|
"project/styles",
|
||||||
|
module,
|
||||||
|
[
|
||||||
|
"styles/rdf-schema-alignment-dialog.css",
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
BIN
extensions/rdf-exporter/module/MOD-INF/lib/arq-2.7.0.jar
Executable file
BIN
extensions/rdf-exporter/module/MOD-INF/lib/arq-2.7.0.jar
Executable file
Binary file not shown.
BIN
extensions/rdf-exporter/module/MOD-INF/lib/arq-extra-2.7.0.jar
Executable file
BIN
extensions/rdf-exporter/module/MOD-INF/lib/arq-extra-2.7.0.jar
Executable file
Binary file not shown.
BIN
extensions/rdf-exporter/module/MOD-INF/lib/iri-0.6.jar
Executable file
BIN
extensions/rdf-exporter/module/MOD-INF/lib/iri-0.6.jar
Executable file
Binary file not shown.
BIN
extensions/rdf-exporter/module/MOD-INF/lib/jena-2.6.0.jar
Executable file
BIN
extensions/rdf-exporter/module/MOD-INF/lib/jena-2.6.0.jar
Executable file
Binary file not shown.
BIN
extensions/rdf-exporter/module/MOD-INF/lib/lucene-core-3.0.1.jar
Executable file
BIN
extensions/rdf-exporter/module/MOD-INF/lib/lucene-core-3.0.1.jar
Executable file
Binary file not shown.
BIN
extensions/rdf-exporter/module/MOD-INF/lib/xercesImpl-2.7.1.jar
Executable file
BIN
extensions/rdf-exporter/module/MOD-INF/lib/xercesImpl-2.7.1.jar
Executable file
Binary file not shown.
4
extensions/rdf-exporter/module/MOD-INF/module.properties
Executable file
4
extensions/rdf-exporter/module/MOD-INF/module.properties
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
name = rdf-exporter
|
||||||
|
description = Freebase Gridworks RDF export
|
||||||
|
templating = false
|
||||||
|
requires = core
|
@ -0,0 +1,76 @@
|
|||||||
|
MenuBar.insertBefore(
|
||||||
|
[ "core/project", "core/export", "core/export-templating" ],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"label":"RDF as RDF/XML",
|
||||||
|
"click": function() { RdfExporterMenuBar.exportRDF("rdf", "rdf"); }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label":"RDF as Turtle",
|
||||||
|
"click": function() { RdfExporterMenuBar.exportRDF("n3", "ttl"); }
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
MenuBar.insertBefore(
|
||||||
|
[ "core/schemas", "core/load-info-freebase" ],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
label: "Edit RDF Schema...",
|
||||||
|
click: function() { RdfExporterMenuBar.editRdfSchema(false); }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Reset RDF Schema...",
|
||||||
|
click: function() { RdfExporterMenuBar.editRdfSchema(true); }
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
RdfExporterMenuBar = {};
|
||||||
|
|
||||||
|
RdfExporterMenuBar.exportRDF = function(format, ext) {
|
||||||
|
if (!theProject.overlayModels.rdfSchema) {
|
||||||
|
alert(
|
||||||
|
"You haven't done any RDF schema alignment yet!"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
RdfExporterMenuBar.rdfExportRows(format, ext);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfExporterMenuBar.rdfExportRows = function(format, ext) {
|
||||||
|
var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
|
||||||
|
var form = document.createElement("form");
|
||||||
|
$(form)
|
||||||
|
.css("display", "none")
|
||||||
|
.attr("method", "post")
|
||||||
|
.attr("action", "/command/export-rows/" + name + "." + ext)
|
||||||
|
.attr("target", "gridworks-export");
|
||||||
|
|
||||||
|
$('<input />')
|
||||||
|
.attr("name", "engine")
|
||||||
|
.attr("value", JSON.stringify(ui.browsingEngine.getJSON()))
|
||||||
|
.appendTo(form);
|
||||||
|
$('<input />')
|
||||||
|
.attr("name", "project")
|
||||||
|
.attr("value", theProject.id)
|
||||||
|
.appendTo(form);
|
||||||
|
$('<input />')
|
||||||
|
.attr("name", "format")
|
||||||
|
.attr("value", format)
|
||||||
|
.appendTo(form);
|
||||||
|
|
||||||
|
document.body.appendChild(form);
|
||||||
|
|
||||||
|
window.open("about:blank", "gridworks-export");
|
||||||
|
form.submit();
|
||||||
|
|
||||||
|
document.body.removeChild(form);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfExporterMenuBar.editRdfSchema = function(reset) {
|
||||||
|
new RdfSchemaAlignmentDialog(reset ? null : theProject.overlayModels.rdfSchema);
|
||||||
|
};
|
||||||
|
|
135
extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-link.js
Executable file
135
extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-link.js
Executable file
@ -0,0 +1,135 @@
|
|||||||
|
RdfSchemaAlignmentDialog.UILink = function(dialog, link, table, options, parentUINode) {
|
||||||
|
this._dialog = dialog;
|
||||||
|
this._link = link;
|
||||||
|
this._options = options;
|
||||||
|
this._parentUINode = parentUINode;
|
||||||
|
|
||||||
|
// Make sure target node is there
|
||||||
|
this._link.target = this._link.target || { nodeType: "cell-as-literal" }
|
||||||
|
|
||||||
|
this._tr = table.insertRow(table.rows.length);
|
||||||
|
this._tdMain = this._tr.insertCell(0);
|
||||||
|
this._tdToggle = this._tr.insertCell(1);
|
||||||
|
this._tdDetails = this._tr.insertCell(2);
|
||||||
|
|
||||||
|
$(this._tdMain).addClass("schema-alignment-link-main").attr("width", "250").addClass("padded");
|
||||||
|
$(this._tdToggle).addClass("schema-alignment-link-toggle").attr("width", "1%").addClass("padded");
|
||||||
|
$(this._tdDetails).addClass("schema-alignment-link-details").attr("width", "90%");
|
||||||
|
|
||||||
|
this._collapsedDetailDiv = $('<div></div>').appendTo(this._tdDetails).addClass("padded").html("...");
|
||||||
|
this._expandedDetailDiv = $('<div></div>').appendTo(this._tdDetails).addClass("schema-alignment-detail-container");
|
||||||
|
var self = this;
|
||||||
|
var show = function() {
|
||||||
|
if (self._options.expanded) {
|
||||||
|
self._collapsedDetailDiv.hide();
|
||||||
|
self._expandedDetailDiv.show();
|
||||||
|
} else {
|
||||||
|
self._collapsedDetailDiv.show();
|
||||||
|
self._expandedDetailDiv.hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
show();
|
||||||
|
|
||||||
|
$(this._tdToggle).html(" ");
|
||||||
|
$('<img />')
|
||||||
|
.attr("src", this._options.expanded ? "images/expanded.png" : "images/collapsed.png")
|
||||||
|
.appendTo(this._tdToggle)
|
||||||
|
.click(function() {
|
||||||
|
self._options.expanded = !self._options.expanded;
|
||||||
|
|
||||||
|
$(this).attr("src", self._options.expanded ? "images/expanded.png" : "images/collapsed.png");
|
||||||
|
|
||||||
|
show();
|
||||||
|
});
|
||||||
|
|
||||||
|
this._renderMain();
|
||||||
|
this._renderDetails();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UILink.prototype._renderMain = function() {
|
||||||
|
$(this._tdMain).empty();
|
||||||
|
var l = this._getTypeName(this._link);
|
||||||
|
var label = l || "property?";
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
$('<img />')
|
||||||
|
.attr("title", "remove property")
|
||||||
|
.attr("src", "images/close.png")
|
||||||
|
.css("cursor", "pointer")
|
||||||
|
.prependTo(this._tdMain)
|
||||||
|
.click(function() {
|
||||||
|
window.setTimeout(function() {
|
||||||
|
self._parentUINode.removeLink(self);
|
||||||
|
self._tr.parentNode.removeChild(self._tr);
|
||||||
|
//self._dialog.preview();
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
var a = $('<a href="javascript:{}"></a>')
|
||||||
|
.addClass("schema-alignment-link-tag")
|
||||||
|
.html(label)
|
||||||
|
.appendTo(this._tdMain)
|
||||||
|
.click(function(evt) {
|
||||||
|
self._startEditProperty(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('<img />').attr("src", "images/arrow-start.png").prependTo(a);
|
||||||
|
$('<img />').attr("src", "images/arrow-end.png").appendTo(a);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UILink.prototype._renderDetails = function() {
|
||||||
|
if (this._targetUI) {
|
||||||
|
this._targetUI.dispose();
|
||||||
|
}
|
||||||
|
if (this._tableDetails) {
|
||||||
|
this._tableDetails.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
this._tableDetails = $('<table></table>').addClass("schema-alignment-table-layout").appendTo(this._expandedDetailDiv);
|
||||||
|
this._targetUI = new RdfSchemaAlignmentDialog.UINode(
|
||||||
|
this._dialog,
|
||||||
|
this._link.target,
|
||||||
|
this._tableDetails[0],
|
||||||
|
{ expanded: "links" in this._link.target && this._link.target.links.length > 0 });
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UILink.prototype._startEditProperty = function(elmt) {
|
||||||
|
var self = this;
|
||||||
|
//default value
|
||||||
|
var def='';
|
||||||
|
if(self._link.target!==null && "columnName" in self._link.target){
|
||||||
|
def = URL.urlify(self._link.target.columnName).toLowerCase();
|
||||||
|
}
|
||||||
|
new RdfSchemaAlignmentDialog.RdfResourceDialog(elmt,'property',function(obj){
|
||||||
|
self._link.uri = obj.id;
|
||||||
|
self._link.curie = obj.name;
|
||||||
|
self._renderMain();
|
||||||
|
},def
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UILink.prototype._getTypeName = function(t){
|
||||||
|
if(t.curie !== undefined && t.curie !==''){
|
||||||
|
return t.curie;
|
||||||
|
}else{
|
||||||
|
return t.uri;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UILink.prototype.getJSON = function() {
|
||||||
|
if ("uri" in this._link && this._link.uri !== null &&
|
||||||
|
"target" in this._link && this._link.target !== null) {
|
||||||
|
|
||||||
|
var targetJSON = this._targetUI.getJSON();
|
||||||
|
if (targetJSON !== null) {
|
||||||
|
return {
|
||||||
|
uri: this._link.uri,
|
||||||
|
curie:this._link.curie,
|
||||||
|
target: targetJSON
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
838
extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-node.js
Executable file
838
extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-node.js
Executable file
@ -0,0 +1,838 @@
|
|||||||
|
RdfSchemaAlignmentDialog.UINode = function(dialog, node, table, options) {
|
||||||
|
this._dialog = dialog;
|
||||||
|
this._node = node;
|
||||||
|
this._options = options;
|
||||||
|
|
||||||
|
this._linkUIs = [];
|
||||||
|
this._detailsRendered = false;
|
||||||
|
|
||||||
|
this._tr = table.insertRow(table.rows.length);
|
||||||
|
this._tdMain = this._tr.insertCell(0);
|
||||||
|
this._tdToggle = this._tr.insertCell(1);
|
||||||
|
this._tdDetails = this._tr.insertCell(2);
|
||||||
|
|
||||||
|
$(this._tdMain).addClass("schema-alignment-node-main").attr("width", "250").addClass("padded");
|
||||||
|
$(this._tdToggle).addClass("schema-alignment-node-toggle").attr("width", "1%").addClass("padded").hide();
|
||||||
|
$(this._tdDetails).addClass("schema-alignment-node-details").attr("width", "90%").hide();
|
||||||
|
|
||||||
|
|
||||||
|
this._renderMain();
|
||||||
|
//this._renderTypes();
|
||||||
|
|
||||||
|
this._expanded = options.expanded;
|
||||||
|
if (this._isExpandable()) {
|
||||||
|
this._showExpandable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._renderMain = function() {
|
||||||
|
$(this._tdMain).empty();
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var type_html = !this._isExpandable()? '' : '<tr>' +
|
||||||
|
'<td>' +
|
||||||
|
'<table bind="rdfTypesTable">' +
|
||||||
|
'<tr bind="rdfTypesTr"><td bind="rdfTypesTd"> </td></tr>' +
|
||||||
|
'<tr bind="addRdfTyprTr">' +
|
||||||
|
'<td>' +
|
||||||
|
'<div class="padded">' +
|
||||||
|
'<a bind="addRdfTypeLink" href="#" class="action">add rdf:type</a>' +
|
||||||
|
'</div>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'</table>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>';
|
||||||
|
var html = $(
|
||||||
|
'<table>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td bind="nodeLabel">' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
type_html +
|
||||||
|
'</table>'
|
||||||
|
).appendTo(this._tdMain)
|
||||||
|
;
|
||||||
|
|
||||||
|
var elmts = DOM.bind(html);
|
||||||
|
this._tdNodeLabel = elmts.nodeLabel;
|
||||||
|
if(elmts.addRdfTypeLink){
|
||||||
|
var typesTable = $('<table></table>')[0];
|
||||||
|
if(self._node.rdfTypes && self._node.rdfTypes.length>0){
|
||||||
|
var func = function(i){
|
||||||
|
return function(){
|
||||||
|
self._removeRdfType(i);
|
||||||
|
self._renderMain();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
for(var i=0;i<self._node.rdfTypes.length;i++){
|
||||||
|
//var f = func(i);
|
||||||
|
var tr = typesTable.insertRow(typesTable.rows.length);
|
||||||
|
var img = $('<img />').attr("title", "remove type").attr("src", "images/close.png").css("cursor", "pointer").click(
|
||||||
|
|
||||||
|
func(i)
|
||||||
|
|
||||||
|
);
|
||||||
|
$(tr).append($('<td>').append(img));
|
||||||
|
$(tr).append($('<td>').text(self._getTypeName(self._node.rdfTypes[i])));
|
||||||
|
}
|
||||||
|
elmts.rdfTypesTd.html(typesTable);
|
||||||
|
}else{
|
||||||
|
elmts.rdfTypesTr.remove();
|
||||||
|
}
|
||||||
|
elmts.addRdfTypeLink.click(function(evt){
|
||||||
|
evt.preventDefault();
|
||||||
|
self._addRdfType(evt.target);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var a = $('<a href="javascript:{}"></a>')
|
||||||
|
.addClass("schema-alignment-node-tag")
|
||||||
|
.appendTo(this._tdNodeLabel)
|
||||||
|
.click(function(evt) {
|
||||||
|
self._showNodeConfigDialog();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this._node.nodeType == "cell-as-resource" ||
|
||||||
|
this._node.nodeType == "cell-as-literal") {
|
||||||
|
|
||||||
|
if(this._node.columnIndex===-1){
|
||||||
|
$('<span></span>')
|
||||||
|
.text('Row Number')
|
||||||
|
.addClass("schema-alignment-node-column")
|
||||||
|
.prependTo(a);
|
||||||
|
}else{
|
||||||
|
if ("columnName" in this._node) {
|
||||||
|
a.html(" cell");
|
||||||
|
|
||||||
|
$('<span></span>')
|
||||||
|
.text(this._node.columnName)
|
||||||
|
.addClass("schema-alignment-node-column")
|
||||||
|
.prependTo(a);
|
||||||
|
} else {
|
||||||
|
a.html(this._options.mustBeCellTopic ? "Which column?" : "Configure...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (this._node.nodeType == "resource") {
|
||||||
|
if ("uri" in this._node) {
|
||||||
|
a.html(this._node.uri);
|
||||||
|
} else {
|
||||||
|
a.html("Which Resource?");
|
||||||
|
}
|
||||||
|
} else if (this._node.nodeType == "literal") {
|
||||||
|
if ("value" in this._node) {
|
||||||
|
a.html(this._node.value);
|
||||||
|
} else {
|
||||||
|
a.html("What value?");
|
||||||
|
}
|
||||||
|
} else if (this._node.nodeType == "blank") {
|
||||||
|
a.html("(blank) ");
|
||||||
|
}else if (this._node.nodeType == "cell-as-blank") {
|
||||||
|
a.html("(blank) cell");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Types
|
||||||
|
/*var aux_table = $('<table>').appendTo($(this._tdMain));
|
||||||
|
aux_table.append($('<tr>').append(td));
|
||||||
|
this._typesTd = $('<td>').attr("width", "250").appendTo($('<tr>').appendTo(aux_table));
|
||||||
|
this._renderTypes();*/
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._isExpandable = function() {
|
||||||
|
return this._node.nodeType == "cell-as-resource" ||
|
||||||
|
this._node.nodeType == "blank" ||
|
||||||
|
this._node.nodeType == "resource" ||
|
||||||
|
this._node.nodeType == "cell-as-blank" ;
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._showExpandable = function() {
|
||||||
|
$(this._tdToggle).show();
|
||||||
|
$(this._tdDetails).show();
|
||||||
|
|
||||||
|
if (this._detailsRendered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._detailsRendered = true;
|
||||||
|
|
||||||
|
this._collapsedDetailDiv = $('<div></div>').appendTo(this._tdDetails).addClass("padded").html("...");
|
||||||
|
this._expandedDetailDiv = $('<div></div>').appendTo(this._tdDetails).addClass("schema-alignment-detail-container");
|
||||||
|
|
||||||
|
this._renderDetails();
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
var show = function() {
|
||||||
|
if (self._expanded) {
|
||||||
|
self._collapsedDetailDiv.hide();
|
||||||
|
self._expandedDetailDiv.show();
|
||||||
|
} else {
|
||||||
|
self._collapsedDetailDiv.show();
|
||||||
|
self._expandedDetailDiv.hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
show();
|
||||||
|
|
||||||
|
$(this._tdToggle).html(" ");
|
||||||
|
$('<img />')
|
||||||
|
.attr("src", this._expanded ? "images/expanded.png" : "images/collapsed.png")
|
||||||
|
.appendTo(this._tdToggle)
|
||||||
|
.click(function() {
|
||||||
|
self._expanded = !self._expanded;
|
||||||
|
|
||||||
|
$(this).attr("src", self._expanded ? "images/expanded.png" : "images/collapsed.png");
|
||||||
|
|
||||||
|
show();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._renderDetails = function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this._tableLinks = $('<table></table>').addClass("schema-alignment-table-layout").appendTo(this._expandedDetailDiv)[0];
|
||||||
|
|
||||||
|
if ("links" in this._node && this._node.links !== null) {
|
||||||
|
for (var i = 0; i < this._node.links.length; i++) {
|
||||||
|
this._linkUIs.push(new RdfSchemaAlignmentDialog.UILink(
|
||||||
|
this._dialog,
|
||||||
|
this._node.links[i],
|
||||||
|
this._tableLinks,
|
||||||
|
{ expanded: true },
|
||||||
|
this
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var divFooter = $('<div></div>').addClass("padded").appendTo(this._expandedDetailDiv);
|
||||||
|
|
||||||
|
$('<a href="javascript:{}"></a>')
|
||||||
|
.addClass("action")
|
||||||
|
.text("add property")
|
||||||
|
.appendTo(divFooter)
|
||||||
|
.click(function() {
|
||||||
|
var newLink = {
|
||||||
|
property: null,
|
||||||
|
target: {
|
||||||
|
nodeType: "cell-as-literal"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
self._linkUIs.push(new RdfSchemaAlignmentDialog.UILink(
|
||||||
|
self._dialog,
|
||||||
|
newLink,
|
||||||
|
self._tableLinks,
|
||||||
|
{
|
||||||
|
expanded: true,
|
||||||
|
mustBeCellTopic: false
|
||||||
|
},
|
||||||
|
self
|
||||||
|
));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._showNodeConfigDialog = function(){
|
||||||
|
var self = this;
|
||||||
|
var frame = DialogSystem.createDialog();
|
||||||
|
|
||||||
|
frame.width("800px");
|
||||||
|
|
||||||
|
var header = $('<div></div>').addClass("dialog-header").text("RDF Node").appendTo(frame);
|
||||||
|
var body = $('<div class="grid-layout layout-full"></div>').addClass("dialog-body").appendTo(frame);
|
||||||
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
* Body
|
||||||
|
*--------------------------------------------------
|
||||||
|
*/
|
||||||
|
var literalTypeSelectHtml =
|
||||||
|
'<option value="untyped" checked>untyped</option>' +
|
||||||
|
'<option value="http://www.w3.org/2001/XMLSchema#int">xsd:int</option>' +
|
||||||
|
'<option value="http://www.w3.org/2001/XMLSchema#double">xsd:double</option>' +
|
||||||
|
//'<option value="/type/float">float</option>' +
|
||||||
|
//'<option value="/type/double">double</option>' +
|
||||||
|
//'<option value="/type/boolean">boolean</option>' +
|
||||||
|
'<option value="http://www.w3.org/2001/XMLSchema#date">xsd:date</option>';
|
||||||
|
|
||||||
|
var html = $(
|
||||||
|
'<table class="layout-normal">' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td>' +
|
||||||
|
'<table class="grid-layout layout-tight">' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td>' +
|
||||||
|
'<div class="schema-align-node-dialog-node-type">' +
|
||||||
|
'<input type="radio" name="schema-align-node-dialog-node-type" value="cell-as" bind="radioNodeTypeCellAs" /> Set to Cell in Column' +
|
||||||
|
'</div>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td>' +
|
||||||
|
'<table class="grid-layout layout-tight">' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td><div class="schema-alignment-node-dialog-column-list" bind="divColumns"></div></td>' +
|
||||||
|
'<td>' +
|
||||||
|
'<table class="grid-layout layout-tight" cols="4">' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td colspan="4">The cell\'s content is used ...</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td><input type="radio" name="schema-align-node-dialog-node-subtype" value="cell-as-resource" bind="radioNodeTypeCellAsResource" /></td>' +
|
||||||
|
'<td colspan="3">as a resource</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td colspan="1">URI:</td>' +
|
||||||
|
'<td colspan="1"><input bind="cellAsResourceUriInput" name="cellAsResourceUri" /></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td colspan="1"><a href="#" bind="previewCellUri">preview/edit</a></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
|
||||||
|
'<tr>' +
|
||||||
|
'<td><input type="radio" name="schema-align-node-dialog-node-subtype" value="cell-as-literal" bind="radioNodeTypeCellAsLiteral" /></td>' +
|
||||||
|
'<td colspan="3">as a literal value</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td colspan="2">Literal type</td>' +
|
||||||
|
'<td colspan="1"><select bind="cellAsLiteralTypeSelect">' + literalTypeSelectHtml + '</select></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td colspan="2">Language (for text)</td>' +
|
||||||
|
'<td colspan="1"><input bind="cellAsLiteralLanguageInput" /></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td><input type="radio" name="schema-align-node-dialog-node-subtype" value="cell-as-blank" bind="radioNodeTypeCellAsBlank" /></td>' +
|
||||||
|
'<td colspan="3">as a blank node</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td colspan="4"><div class="note">* relative URIs will be resolved against base URI</div></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'</table>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'</table>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'</table>' +
|
||||||
|
'</td>' +
|
||||||
|
|
||||||
|
|
||||||
|
'<td>' +
|
||||||
|
'<table class="grid-layout layout-tight">' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td colspan="3">' +
|
||||||
|
'<div class="schema-align-node-dialog-node-type">' +
|
||||||
|
'<input type="radio" name="schema-align-node-dialog-node-type" value="resource" bind="radioNodeTypeResource" /> Use a constant resource' +
|
||||||
|
'</div>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td>URI:</td>' +
|
||||||
|
'<td><input bind="resourceNodeTypeInput" /></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
|
||||||
|
'<tr>' +
|
||||||
|
'<td colspan="3">' +
|
||||||
|
'<div class="schema-align-node-dialog-node-type">' +
|
||||||
|
'<input type="radio" name="schema-align-node-dialog-node-type" value="literal" bind="radioNodeTypeLiteral" /> Use a constant literal value' +
|
||||||
|
'</div>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td>Value</td>' +
|
||||||
|
'<td><input bind="literalNodeTypeValueInput" /></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td>Value type</td>' +
|
||||||
|
'<td><select bind="literalNodeTypeValueTypeSelect">' + literalTypeSelectHtml + '</select></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td></td>' +
|
||||||
|
'<td>Language</td>' +
|
||||||
|
'<td><input bind="literalNodeTypeLanguageInput" /></td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'<tr>' +
|
||||||
|
'<td colspan="3">' +
|
||||||
|
'<div class="schema-align-node-dialog-node-type">' +
|
||||||
|
'<input type="radio" name="schema-align-node-dialog-node-type" value="blank" bind="radioNodeTypeBlank" /> Generate a blank node (shared between all rows)' +
|
||||||
|
'</div>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
|
||||||
|
'</table>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'</table>'
|
||||||
|
).appendTo(body);
|
||||||
|
|
||||||
|
var elmts = DOM.bind(html);
|
||||||
|
|
||||||
|
var tableColumns = $('<table></table>')
|
||||||
|
.attr("cellspacing", "5")
|
||||||
|
.attr("cellpadding", "0")
|
||||||
|
.appendTo(elmts.divColumns)[0];
|
||||||
|
|
||||||
|
var makeColumnChoice = function(column, columnIndex) {
|
||||||
|
var tr = tableColumns.insertRow(tableColumns.rows.length);
|
||||||
|
|
||||||
|
var radio = $('<input />')
|
||||||
|
.attr("type", "radio")
|
||||||
|
//.attr("value", column.name)
|
||||||
|
.attr("value",columnIndex)
|
||||||
|
.attr("name", "schema-align-node-dialog-column")
|
||||||
|
.appendTo(tr.insertCell(0))
|
||||||
|
.click(function() {
|
||||||
|
elmts.radioNodeTypeCellAs[0].checked = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if ((!("columnName" in self._node) || !self._node.columnName) && columnIndex === -1) {
|
||||||
|
radio.attr("checked", "true");
|
||||||
|
} else if (column.name == self._node.columnName) {
|
||||||
|
radio.attr("checked", "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
var td = tr.insertCell(1);
|
||||||
|
if(columnIndex===-1){
|
||||||
|
$(td).addClass('highlighted');
|
||||||
|
}
|
||||||
|
$('<span></span>').text(column.name).appendTo(td);
|
||||||
|
};
|
||||||
|
|
||||||
|
//Add Row Number
|
||||||
|
makeColumnChoice({name:'Row Number'},-1);
|
||||||
|
|
||||||
|
var columns = theProject.columnModel.columns;
|
||||||
|
for (var i = 0; i < columns.length; i++) {
|
||||||
|
makeColumnChoice(columns[i], i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
elmts.cellAsResourceUriInput.attr("disabled","disabled");
|
||||||
|
/* elmts.previewCellUri.add(elmts.radioNodeTypeCellAsResource[0])
|
||||||
|
.bind("click", function() {
|
||||||
|
alert("shifit");
|
||||||
|
elmts.radioNodeTypeCellAs[0].checked=true;
|
||||||
|
elmts.radioNodeTypeCellAsResource[0].checked = true;
|
||||||
|
});*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
elmts.cellAsLiteralTypeSelect.add(elmts.radioNodeTypeCellAsLiteral[0])
|
||||||
|
.bind("focus", function() {
|
||||||
|
elmts.radioNodeTypeCellAs[0].checked=true;
|
||||||
|
elmts.radioNodeTypeCellAsLiteral[0].checked = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
elmts.cellAsLiteralLanguageInput
|
||||||
|
.bind("focus", function() {
|
||||||
|
elmts.radioNodeTypeCellAs[0].checked=true;
|
||||||
|
elmts.radioNodeTypeCellAsLiteral[0].checked = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
elmts.radioNodeTypeCellAsBlank.add(elmts.radioNodeTypeCellAsResource).add(elmts.radioNodeTypeCellAsLiteral).bind("focus", function() {
|
||||||
|
elmts.radioNodeTypeCellAs[0].checked=true;
|
||||||
|
});
|
||||||
|
|
||||||
|
elmts.resourceNodeTypeInput
|
||||||
|
.bind("focus", function() {
|
||||||
|
elmts.radioNodeTypeResource[0].checked = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
elmts.literalNodeTypeValueInput
|
||||||
|
.bind("focus", function() { elmts.radioNodeTypeLiteral[0].checked = true; });
|
||||||
|
|
||||||
|
elmts.literalNodeTypeValueTypeSelect
|
||||||
|
.bind("focus", function() { elmts.radioNodeTypeLiteral[0].checked = true; });
|
||||||
|
|
||||||
|
elmts.literalNodeTypeLanguageInput
|
||||||
|
.bind("focus", function() { elmts.radioNodeTypeLiteral[0].checked = true; });
|
||||||
|
|
||||||
|
|
||||||
|
elmts.resourceNodeTypeInput.add(elmts.literalNodeTypeValueInput[0]).add(elmts.literalNodeTypeValueTypeSelect[0])
|
||||||
|
.add(elmts.literalNodeTypeLanguageInput[0]).add(elmts.radioNodeTypeBlank[0]).add(elmts.radioNodeTypeResource[0])
|
||||||
|
.add(elmts.radioNodeTypeLiteral[0])
|
||||||
|
.bind("focus",function(){
|
||||||
|
elmts.radioNodeTypeCellAsBlank[0].checked = false;
|
||||||
|
elmts.radioNodeTypeCellAsLiteral[0].checked = false;
|
||||||
|
elmts.radioNodeTypeCellAsResource[0].checked = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// elmts.radioNodeTypeCellAsResource[0].checked = true; // just make sure some subtype is selected
|
||||||
|
var uri_expr = "gel:value.urlify(baseURI)";
|
||||||
|
if (this._node.nodeType.match(/^cell-as-/)) {
|
||||||
|
elmts.radioNodeTypeCellAs[0].checked = true;
|
||||||
|
if (this._node.nodeType == "cell-as-resource") {
|
||||||
|
elmts.radioNodeTypeCellAsResource[0].checked = true;
|
||||||
|
uri_expr = this._node.uriExpression || uri_expr;
|
||||||
|
} else if (this._node.nodeType == "cell-as-literal") {
|
||||||
|
elmts.radioNodeTypeCellAsLiteral[0].checked = true;
|
||||||
|
$('>option[value=' +this._node.valueType +']',elmts.cellAsLiteralTypeSelect).attr('selected','selected');
|
||||||
|
} else if (this._node.nodeType == "cell-as-blank") {
|
||||||
|
elmts.radioNodeTypeCellAsBlank[0].checked = true;
|
||||||
|
}
|
||||||
|
} else if (this._node.nodeType == "blank") {
|
||||||
|
elmts.radioNodeTypeBlank[0].checked = true;
|
||||||
|
} else if (this._node.nodeType == "resource") {
|
||||||
|
elmts.radioNodeTypeResource[0].checked = true;
|
||||||
|
if(this._node.uri){
|
||||||
|
elmts.resourceNodeTypeInput.val(this._node.uri);
|
||||||
|
}
|
||||||
|
} else if (this._node.nodeType == "literal") {
|
||||||
|
elmts.radioNodeTypeLiteral[0].checked = true;
|
||||||
|
if(this._node.value){
|
||||||
|
elmts.literalNodeTypeValueInput.val(this._node.value);
|
||||||
|
}
|
||||||
|
$('>option[value=' +this._node.valueType +']',elmts.literalNodeTypeValueTypeSelect).attr('selected','selected');
|
||||||
|
}
|
||||||
|
|
||||||
|
elmts.cellAsResourceUriInput.val(uri_expr);
|
||||||
|
|
||||||
|
//preview/edit URI
|
||||||
|
//elmts.cellAsResourceUriInput.attr("disabled","disabled").val('"' + RdfSchemaAlignment._defaultNamespace + '" + value.urlify()');
|
||||||
|
elmts.previewCellUri.click(function(evt){
|
||||||
|
evt.preventDefault();
|
||||||
|
var cellIndex = $("input[name='schema-align-node-dialog-column']:checked")[0].value;
|
||||||
|
var expr = $("input[name='cellAsResourceUri']").val();
|
||||||
|
self._previewURI(expr,cellIndex,elmts);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
* Footer
|
||||||
|
*--------------------------------------------------
|
||||||
|
*/
|
||||||
|
var getResultJSON = function() {
|
||||||
|
var node = {
|
||||||
|
nodeType: $("input[name='schema-align-node-dialog-node-type']:checked")[0].value
|
||||||
|
};
|
||||||
|
if (node.nodeType == "cell-as") {
|
||||||
|
node.nodeType = $("input[name='schema-align-node-dialog-node-subtype']:checked")[0].value;
|
||||||
|
|
||||||
|
node.columnIndex = parseInt($("input[name='schema-align-node-dialog-column']:checked")[0].value);
|
||||||
|
if(node.columnIndex!==-1){
|
||||||
|
node.columnName = theProject.columnModel.columns[node.columnIndex].name;
|
||||||
|
}else{
|
||||||
|
node.isRowNumberCell = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.nodeType == "cell-as-resource") {
|
||||||
|
node.uriExpression = elmts.cellAsResourceUriInput[0].value;
|
||||||
|
} else if (node.nodeType == "cell-as-literal") {
|
||||||
|
node.valueType = elmts.cellAsLiteralTypeSelect[0].value;
|
||||||
|
|
||||||
|
if (node.valueType == "untyped") {
|
||||||
|
var l = elmts.cellAsLiteralLanguageInput[0].value;
|
||||||
|
node.lang = l;
|
||||||
|
}
|
||||||
|
} else if (node.nodeType == "cell-as-blank") {
|
||||||
|
//DO NOTHING
|
||||||
|
}
|
||||||
|
} else if (node.nodeType == "blank") {
|
||||||
|
//DO NOTHING
|
||||||
|
} else if (node.nodeType == "resource") {
|
||||||
|
node.uri = elmts.resourceNodeTypeInput[0].value;
|
||||||
|
if (!node.uri.length) {
|
||||||
|
alert("Please specify the URI to use.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else if (node.nodeType == "literal") {
|
||||||
|
node.value = $.trim(elmts.literalNodeTypeValueInput[0].value);
|
||||||
|
if (!node.value.length) {
|
||||||
|
alert("Please specify the value to use.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
node.valueType = elmts.literalNodeTypeValueTypeSelect[0].value;
|
||||||
|
|
||||||
|
if (node.valueType == "untyped") {
|
||||||
|
node.lang = elmts.literalNodeTypeLanguageInput[0].value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
};
|
||||||
|
|
||||||
|
$('<button></button>').html(" OK ").click(function() {
|
||||||
|
var node = getResultJSON();
|
||||||
|
if(self._node.rdfTypes){
|
||||||
|
node.rdfTypes = cloneDeep(self._node.rdfTypes);
|
||||||
|
}
|
||||||
|
if (node !== null) {
|
||||||
|
DialogSystem.dismissUntil(level - 1);
|
||||||
|
|
||||||
|
self._node = node;
|
||||||
|
/*if('columnIndex' in node){
|
||||||
|
if(node.columnIndex!==-1){
|
||||||
|
self._node.columnName = theProject.columnModel.columns[node.columnIndex].name;
|
||||||
|
}else{
|
||||||
|
self._node.isRowNumberCell = true;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
self.render();
|
||||||
|
//self._dialog.preview();
|
||||||
|
}
|
||||||
|
}).appendTo(footer);
|
||||||
|
|
||||||
|
$('<button></button>').text("Cancel").click(function() {
|
||||||
|
DialogSystem.dismissUntil(level - 1);
|
||||||
|
}).appendTo(footer);
|
||||||
|
|
||||||
|
|
||||||
|
var level = DialogSystem.showDialog(frame);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._previewURI = function(expr,cellIndex,elmts){
|
||||||
|
var self = this;
|
||||||
|
//FIXME
|
||||||
|
cellIndex = cellIndex==='-1'?0:cellIndex;
|
||||||
|
DataTableView.promptExpressionOnVisibleRows(
|
||||||
|
{
|
||||||
|
"cellIndex":cellIndex
|
||||||
|
},
|
||||||
|
"Custom Facet on column ",
|
||||||
|
expr,
|
||||||
|
function(expression){
|
||||||
|
expression = expression.substring(4);
|
||||||
|
$("input[name='cellAsResourceUri']").val(expression);
|
||||||
|
elmts.radioNodeTypeCellAs[0].checked=true;
|
||||||
|
elmts.radioNodeTypeCellAsResource[0].checked = true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype.render = function() {
|
||||||
|
this._renderMain();
|
||||||
|
if (this._isExpandable()) {
|
||||||
|
this._showExpandable();
|
||||||
|
} else {
|
||||||
|
this._hideExpandable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype.removeLink = function(linkUI) {
|
||||||
|
for (var i = this._linkUIs.length - 1; i >= 0; i--) {
|
||||||
|
if (this._linkUIs[i] === linkUI) {
|
||||||
|
this._linkUIs.splice(i, 1);
|
||||||
|
this._node.links.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._hideExpandable = function() {
|
||||||
|
$(this._tdToggle).hide();
|
||||||
|
$(this._tdDetails).hide();
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._addRdfType = function(src){
|
||||||
|
var self = this;
|
||||||
|
new RdfSchemaAlignmentDialog.RdfResourceDialog(src,'class', function (obj) {
|
||||||
|
self._addNodeRdfType(obj.id,obj.name);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._removeRdfType = function(index){
|
||||||
|
var self = this;
|
||||||
|
self._node.rdfTypes.splice(index,1);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._addNodeRdfType = function(uri,curie){
|
||||||
|
if(!this._node.rdfTypes){
|
||||||
|
this._node.rdfTypes = [];
|
||||||
|
}
|
||||||
|
this._node.rdfTypes.push({uri:uri,curie:curie});
|
||||||
|
this._renderMain();
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype._getTypeName = function(t){
|
||||||
|
if(!t){return '';}
|
||||||
|
if(t.curie !== undefined && t.curie!==''){
|
||||||
|
return t.curie;
|
||||||
|
}else{
|
||||||
|
return t.uri;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.UINode.prototype.getJSON = function() {
|
||||||
|
var result = null;
|
||||||
|
var getLinks = false;
|
||||||
|
|
||||||
|
if (this._node.nodeType.match(/^cell-as-/)) {
|
||||||
|
if (!("columnIndex" in this._node || this._node.isRowNumberCell) || this._node.columnIndex===undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._node.nodeType == "cell-as-resource") {
|
||||||
|
if (!this._node.isRowNumberCell){
|
||||||
|
result = {
|
||||||
|
nodeType: this._node.nodeType,
|
||||||
|
columnIndex: this._node.columnIndex,
|
||||||
|
uriExpression: this._node.uriExpression,
|
||||||
|
isRowNumberCell: this._node.isRowNumberCell || false,
|
||||||
|
columnName: this._node.columnName
|
||||||
|
// type: "type" in this._node ? cloneDeep(this._node.type) : { "id" : "/common/topic", "name" : "Topic", "cvt" : false }
|
||||||
|
};
|
||||||
|
}else{
|
||||||
|
result = {
|
||||||
|
nodeType: this._node.nodeType,
|
||||||
|
columnIndex: this._node.columnIndex,
|
||||||
|
uriExpression: this._node.uriExpression,
|
||||||
|
isRowNumberCell: this._node.isRowNumberCell || false
|
||||||
|
// type: "type" in this._node ? cloneDeep(this._node.type) : { "id" : "/common/topic", "name" : "Topic", "cvt" : false }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
getLinks = true;
|
||||||
|
} else if (this._node.nodeType == "cell-as-literal") {
|
||||||
|
result = {
|
||||||
|
nodeType: this._node.nodeType,
|
||||||
|
columnIndex: this._node.columnIndex,
|
||||||
|
valueType: "valueType" in this._node ? this._node.valueType : "untyped",
|
||||||
|
lang: "lang" in this._node ? this._node.lang : "en",
|
||||||
|
columnName: this._node.columnName
|
||||||
|
};
|
||||||
|
} else if (this._node.nodeType == "cell-as-blank") {
|
||||||
|
result = {
|
||||||
|
nodeType: this._node.nodeType,
|
||||||
|
columnIndex: this._node.columnIndex,
|
||||||
|
columnName: this._node.columnName
|
||||||
|
};
|
||||||
|
getLinks = true;
|
||||||
|
}
|
||||||
|
} else if (this._node.nodeType == "resource") {
|
||||||
|
result = {
|
||||||
|
nodeType: this._node.nodeType,
|
||||||
|
uri: this._node.uri
|
||||||
|
};
|
||||||
|
getLinks = true;
|
||||||
|
} else if (this._node.nodeType == "literal") {
|
||||||
|
if (!("value" in this._node) || !this._node.value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
result = {
|
||||||
|
nodeType: this._node.nodeType,
|
||||||
|
value: this._node.value,
|
||||||
|
valueType: "valueType" in this._node ? this._node.valueType : "untyped",
|
||||||
|
lang: "lang" in this._node ? this._node.lang : "en"
|
||||||
|
};
|
||||||
|
} else if (this._node.nodeType == "blank") {
|
||||||
|
result = {
|
||||||
|
nodeType: this._node.nodeType,
|
||||||
|
columnIndex: this._node.columnIndex
|
||||||
|
};
|
||||||
|
getLinks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (getLinks) {
|
||||||
|
var rdfTypes = [];
|
||||||
|
if(this._node.rdfTypes){
|
||||||
|
for(var i=0;i<this._node.rdfTypes.length; i++){
|
||||||
|
rdfTypes.push({uri:this._node.rdfTypes[i].uri,
|
||||||
|
curie:this._node.rdfTypes[i].curie
|
||||||
|
});
|
||||||
|
}
|
||||||
|
result.rdfTypes = rdfTypes;
|
||||||
|
}
|
||||||
|
var links = [];
|
||||||
|
for (var i = 0; i < this._linkUIs.length; i++) {
|
||||||
|
var link = this._linkUIs[i].getJSON();
|
||||||
|
if (link !== null) {
|
||||||
|
links.push(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.links = links;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.NewRdfResourceDialog = function(elmt,defaultVal,onDone){
|
||||||
|
var menu = MenuSystem.createMenu().width('400px');
|
||||||
|
menu.html('<div class="schema-alignment-link-menu-type-search">' +
|
||||||
|
'<span class="schema-alignment-node-column">URI: <small>(relative URIs will be resolved against base URI)</small></span>' +
|
||||||
|
'<input type="text" bind="newResourceUri" size="50"><br/>' +
|
||||||
|
'<button bind="applyBtn">Apply</button>' +
|
||||||
|
'<button bind="cancelBtn">Cancel</button>'
|
||||||
|
//'<input type="text" bind="newResourceUri2" size="50" style="display:none">'
|
||||||
|
);
|
||||||
|
MenuSystem.showMenu(menu,function(){});
|
||||||
|
MenuSystem.positionMenuLeftRight(menu, $(elmt));
|
||||||
|
var elmts = DOM.bind(menu);
|
||||||
|
elmts.newResourceUri.val(defaultVal).focus().select();
|
||||||
|
elmts.cancelBtn.click(function(){
|
||||||
|
MenuSystem.dismissAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
elmts.applyBtn.click(function(){
|
||||||
|
var val = elmts.newResourceUri.val();
|
||||||
|
if(!val){
|
||||||
|
alert('Enter URI');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MenuSystem.dismissAll();
|
||||||
|
if(val.substring(0,1)===':'){
|
||||||
|
val = val.substring(1);
|
||||||
|
}
|
||||||
|
var obj = {
|
||||||
|
id:val,
|
||||||
|
name:val.match('^http://')?val:':'+val
|
||||||
|
};
|
||||||
|
onDone(obj);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
RdfSchemaAlignmentDialog.RdfResourceDialog = function(elmt,lookFor,onDone,defaultVal){
|
||||||
|
var menu = MenuSystem.createMenu().width('400px');
|
||||||
|
menu.html('<div class="schema-alignment-link-menu-type-search">' +
|
||||||
|
'<span>Search for ' + lookFor + ':</span>' +
|
||||||
|
'<input type="text" bind="newResourceUri" >'
|
||||||
|
//'<input type="text" bind="newResourceUri2" size="50" style="display:none">'
|
||||||
|
);
|
||||||
|
MenuSystem.showMenu(menu,function(){});
|
||||||
|
MenuSystem.positionMenuLeftRight(menu, $(elmt));
|
||||||
|
var elmts = DOM.bind(menu);
|
||||||
|
|
||||||
|
/*elmts.createOne.click(function(evt){
|
||||||
|
evt.preventDefault();
|
||||||
|
MenuSystem.dismissAll();
|
||||||
|
new RdfSchemaAlignmentDialog.NewRdfResourceDialog(elmt,defaultVal||'',onDone);
|
||||||
|
});*/
|
||||||
|
//Autocomplete
|
||||||
|
/*elmts.newResourceUri.autoComplete({
|
||||||
|
script:'/command/search-vocabularies?type=' + lookFor + '&',
|
||||||
|
varname:'input',
|
||||||
|
json:true,
|
||||||
|
shownoresults:true,
|
||||||
|
maxresults:16,
|
||||||
|
cache:false,
|
||||||
|
timeout:null,
|
||||||
|
minchars:2,
|
||||||
|
callback: function (obj) {
|
||||||
|
MenuSystem.dismissAll();
|
||||||
|
if(onDone){
|
||||||
|
onDone(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
elmts.newResourceUri.focus();*/
|
||||||
|
|
||||||
|
elmts.newResourceUri.suggestterm({type_strict:lookFor}).bind('fb-select',function(e,data){
|
||||||
|
MenuSystem.dismissAll();
|
||||||
|
if(onDone){
|
||||||
|
onDone(data);
|
||||||
|
}
|
||||||
|
}).bind('fb-select-new',function(e,val){
|
||||||
|
MenuSystem.dismissAll();
|
||||||
|
new RdfSchemaAlignmentDialog.NewRdfResourceDialog(elmt,defaultVal||'',onDone);
|
||||||
|
});
|
||||||
|
elmts.newResourceUri.focus();
|
||||||
|
};
|
313
extensions/rdf-exporter/module/scripts/rdf-schema-alignment.js
Executable file
313
extensions/rdf-exporter/module/scripts/rdf-schema-alignment.js
Executable file
@ -0,0 +1,313 @@
|
|||||||
|
var RdfSchemaAlignment = {};
|
||||||
|
|
||||||
|
function RdfSchemaAlignmentDialog(schema){
|
||||||
|
this._originalSchema = schema || { rootNodes: [] };
|
||||||
|
this._schema = cloneDeep(this._originalSchema); // this is what can be munched on
|
||||||
|
|
||||||
|
if (!this._schema.rootNodes.length) {
|
||||||
|
this._schema.rootNodes.push(RdfSchemaAlignment.createNewRootNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
//this._schema = { rootNodes: [] };
|
||||||
|
//this._schema.rootNodes.push(RdfSchemaAlignment.createNewRootNode());
|
||||||
|
this._nodeUIs = [];
|
||||||
|
this._createDialog();
|
||||||
|
|
||||||
|
RdfSchemaAlignment._defaultNamespace = this._schema.baseUri;
|
||||||
|
this._replaceBaseUri(RdfSchemaAlignment._defaultNamespace || URL.getHostname()+'/');
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype._createDialog = function() {
|
||||||
|
var self = this;
|
||||||
|
var frame = DialogSystem.createDialog();
|
||||||
|
|
||||||
|
frame.width("1000px");
|
||||||
|
|
||||||
|
var header = $('<div></div>').addClass("dialog-header").text("RDF Schema Alignment").appendTo(frame);
|
||||||
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
||||||
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
||||||
|
|
||||||
|
this._constructFooter(footer);
|
||||||
|
this._constructBody(body);
|
||||||
|
|
||||||
|
this._level = DialogSystem.showDialog(frame);
|
||||||
|
|
||||||
|
this._renderBody(body);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype._constructFooter = function(footer) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
$('<button></button>').html(" OK ").click(function() {
|
||||||
|
var schema = self.getJSON();
|
||||||
|
Gridworks.postProcess(
|
||||||
|
"save-rdf-schema",
|
||||||
|
{},
|
||||||
|
{ schema: JSON.stringify(schema) },
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
onDone: function() {
|
||||||
|
DialogSystem.dismissUntil(self._level - 1);
|
||||||
|
theProject.schema = schema;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}).appendTo(footer);
|
||||||
|
|
||||||
|
$('<button></button>').text("Cancel").click(function() {
|
||||||
|
DialogSystem.dismissUntil(self._level - 1);
|
||||||
|
}).appendTo(footer);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype._constructBody = function(body) {
|
||||||
|
var self = this;
|
||||||
|
$('<p>' +
|
||||||
|
'RDF Schema Alignment... node types are: cell-as-resource, cell-as-literal, cell-as-blank, literal, resource, and blank' +
|
||||||
|
'</p>').appendTo(body);
|
||||||
|
|
||||||
|
var html = $(
|
||||||
|
'<p>Base URI: <span bind="baseUriSpan" class="emphasized"></span> <a href="#" bind="editBaseUriLink">edit</a></p>'+
|
||||||
|
'<div id="rdf-schema-alignment-tabs" class="gridworks-tabs">' +
|
||||||
|
'<ul>' +
|
||||||
|
'<li><a href="#rdf-schema-alignment-tabs-schema">RDF Skeleton</a></li>' +
|
||||||
|
'<li><a href="#rdf-schema-alignment-tabs-preview">RDF Preview</a></li>' +
|
||||||
|
'<li><a href="#rdf-schema-alignment-tabs-vocabulary-manager">Vocabulary Manager</a></li>' +
|
||||||
|
'</ul>' +
|
||||||
|
'<div id="rdf-schema-alignment-tabs-schema">' +
|
||||||
|
'<div class="schema-alignment-dialog-canvas rdf-schema-alignment-dialog-canvas"></div>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div id="rdf-schema-alignment-tabs-preview" style="display: none;">' +
|
||||||
|
'<div class="schema-alignment-dialog-preview" id="rdf-schema-alignment-dialog-preview"></div>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div id="rdf-schema-alignment-tabs-vocabulary-manager" style="display: none;">' +
|
||||||
|
'<div id="rdf-vocabulary-manager" class="schema-alignment-dialog-preview"></div>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>'
|
||||||
|
).appendTo(body);
|
||||||
|
var elmts = DOM.bind(html);
|
||||||
|
this._baseUriSpan = elmts.baseUriSpan;
|
||||||
|
elmts.baseUriSpan.text(RdfSchemaAlignment._defaultNamespace);
|
||||||
|
|
||||||
|
elmts.editBaseUriLink.click(function(evt){
|
||||||
|
evt.preventDefault();
|
||||||
|
self._editBaseUri($(evt.target));
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype._previewRdf = function(){
|
||||||
|
var self = this;
|
||||||
|
var schema = this.getJSON();
|
||||||
|
self._previewPane.empty().html('<img src="images/large-spinner.gif" title="loading..."/>');
|
||||||
|
$.post(
|
||||||
|
"/command/preview-rdf?" + $.param({ project: theProject.id }),
|
||||||
|
{ schema: JSON.stringify(schema), engine: JSON.stringify(ui.browsingEngine.getJSON()) },
|
||||||
|
function(data) {
|
||||||
|
self._previewPane.empty();
|
||||||
|
self._previewPane.text(data.v);
|
||||||
|
},
|
||||||
|
"json"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype._renderBody = function(body) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
$("#rdf-schema-alignment-tabs").tabs({
|
||||||
|
select:function(evt,tabs){
|
||||||
|
if(tabs.index===1){
|
||||||
|
self._previewRdf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#rdf-schema-alignment-tabs-preview").css("display", "");
|
||||||
|
$("#rdf-schema-alignment-tabs-vocabulary-manager").css("display", "");
|
||||||
|
|
||||||
|
this._canvas = $(".schema-alignment-dialog-canvas");
|
||||||
|
this._nodeTable = $('<table></table>').addClass("schema-alignment-table-layout").appendTo(this._canvas)[0];
|
||||||
|
|
||||||
|
for (var i = 0; i < this._schema.rootNodes.length; i++) {
|
||||||
|
this._nodeUIs.push(new RdfSchemaAlignmentDialog.UINode(
|
||||||
|
this,
|
||||||
|
this._schema.rootNodes[i],
|
||||||
|
this._nodeTable,
|
||||||
|
{
|
||||||
|
expanded: true,
|
||||||
|
mustBeCellTopic: true
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
this._previewPane = $("#rdf-schema-alignment-dialog-preview");
|
||||||
|
|
||||||
|
this._vocabularyManager = $("#rdf-vocabulary-manager");
|
||||||
|
var vocab_html = $(
|
||||||
|
'<div id="vocabulary-list" bind="vocabularyList" class="vocabulary-manager-list">' +
|
||||||
|
'</div>' +
|
||||||
|
'<div id="new-vocabulary" bind="newVocabulary" class="vocabulary-manager-footer">' +
|
||||||
|
'</div>'
|
||||||
|
);
|
||||||
|
var elmts = DOM.bind(vocab_html);
|
||||||
|
this._vocabularyManager.html(vocab_html);
|
||||||
|
this._vocabularyListContainer = elmts.vocabularyList;
|
||||||
|
this._newVocabularyContainer = elmts.newVocabulary;
|
||||||
|
this._listVocabularies();
|
||||||
|
};
|
||||||
|
//TODO refactor vocabulary manager into its stand-alone Javascript object (~Class)
|
||||||
|
RdfSchemaAlignmentDialog.prototype._listVocabularies = function(){
|
||||||
|
var self = this;
|
||||||
|
self._vocabularyListContainer.empty();
|
||||||
|
self._renderVocabularyFooter();
|
||||||
|
|
||||||
|
|
||||||
|
$.get("/command/list-vocabularies",{},function(o){
|
||||||
|
var vocab_table = $('<table></table>').width('100%').addClass('data-table')[0];
|
||||||
|
var tr = vocab_table.insertRow(vocab_table.rows.length);
|
||||||
|
$(tr).addClass('');
|
||||||
|
$(tr).html('<td></td><td>Prefix</td><td>Namespace</td>');
|
||||||
|
$('td',tr).addClass('column-header');
|
||||||
|
for(var i=0;i<o.vocabularies.length;i++){
|
||||||
|
var vocabulary = o.vocabularies[i];
|
||||||
|
var tr = vocab_table.insertRow(vocab_table.rows.length);
|
||||||
|
$(tr).addClass(i%2==0?'even':'odd');
|
||||||
|
var td = tr.insertCell(0);
|
||||||
|
var getDelFunc = function(){
|
||||||
|
var vocab_uri = vocabulary.uri;
|
||||||
|
return function(){self._deleteVocabulary(vocab_uri);}
|
||||||
|
}();
|
||||||
|
var del_link = $('<a>').html('<img title="remove vocabulary" src="images/close.png" style="cursor: pointer;" />').click(getDelFunc).appendTo($(td));
|
||||||
|
|
||||||
|
td = tr.insertCell(1);
|
||||||
|
$(td).text(vocabulary.name );
|
||||||
|
td = tr.insertCell(2);
|
||||||
|
$(td).text(vocabulary.uri);
|
||||||
|
}
|
||||||
|
$(vocab_table).appendTo(self._vocabularyListContainer);
|
||||||
|
},"json");
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype._renderVocabularyFooter = function(){
|
||||||
|
var self = this;
|
||||||
|
self._newVocabularyContainer.empty();
|
||||||
|
var html = $(
|
||||||
|
'<h2>Add New:</h2>' +
|
||||||
|
'<form>'+
|
||||||
|
'<table width="900px">' +
|
||||||
|
'<tr><td>prefix:</td><td> <input type="text" bind="prefix" size="12"></td><td> e.g. rdf, rdfs, foaf, skos, dcat...</td></tr>' +
|
||||||
|
'<tr><td>url:</td><td> <input type="text" bind="url" size="40"></td><td> The URL where vocabulary definition can be obtained as RDF/XML</td></tr>' +
|
||||||
|
'<tr><td>namespace:</td><td> <input type="text" bind="namespace" size="40"></td><td> <span>The namespace under which vocabulary classes and properties are defined (only those will be imported)</span><br/><span> it is usually the same as the URL.</span> </td></tr>' +
|
||||||
|
'<tr><td colspan="3"><input type="submit" bind="addvocab" id="addvocab-submit" value="Import Vocabulary"></td></tr>' +
|
||||||
|
'</table>' +
|
||||||
|
'</form>'
|
||||||
|
);
|
||||||
|
|
||||||
|
var elmts = DOM.bind(html);
|
||||||
|
elmts.addvocab.click(function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
var prefix = elmts.prefix.val();
|
||||||
|
var namespace = elmts.namespace.val();
|
||||||
|
var url = elmts.url.val();
|
||||||
|
if(!(prefix && namespace && url)){
|
||||||
|
alert('Please enter all required parameters');
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
var dismissBusy = DialogSystem.showBusy('Importing vocabulary from: ' + url);
|
||||||
|
$.get("/command/import-vocabulary",{prefix:prefix,namespace:namespace,url:url},function(data){
|
||||||
|
dismissBusy();
|
||||||
|
if (data.code === "error"){
|
||||||
|
alert('Error:' + data.message)
|
||||||
|
}else{
|
||||||
|
self._listVocabularies();
|
||||||
|
}
|
||||||
|
},"json");
|
||||||
|
});
|
||||||
|
|
||||||
|
html.appendTo(self._newVocabularyContainer);
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype._deleteVocabulary = function(uri){
|
||||||
|
var self = this;
|
||||||
|
var dismissBusy = DialogSystem.showBusy('Deleteing vocabulary: ' + uri);
|
||||||
|
$.post("/command/delete-vocabulary",{uri:uri},function(data){
|
||||||
|
dismissBusy();
|
||||||
|
if (data.code === "error"){
|
||||||
|
alert('Error:' + data.message)
|
||||||
|
}else{
|
||||||
|
self._listVocabularies();
|
||||||
|
}
|
||||||
|
},"json");
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignment.createNewRootNode = function() {
|
||||||
|
var links = [];
|
||||||
|
var columns = theProject.columnModel.columns;
|
||||||
|
for (var i = 0; i < columns.length; i++) {
|
||||||
|
var column = columns[i];
|
||||||
|
var target = {
|
||||||
|
nodeType: "cell-as-literal",
|
||||||
|
columnName: column.name,
|
||||||
|
columnIndex:i
|
||||||
|
};
|
||||||
|
links.push({
|
||||||
|
uri: null,
|
||||||
|
curie:null,
|
||||||
|
target: target
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
rootNode = { nodeType: "cell-as-resource", uriExpression:"gel:row.index.urlify(baseURI)", columnIndex:-1, isRowNumberCell:true};
|
||||||
|
rootNode.links = links;
|
||||||
|
|
||||||
|
return rootNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype._editBaseUri = function(src){
|
||||||
|
var self = this;
|
||||||
|
var menu = MenuSystem.createMenu().width('400px');
|
||||||
|
menu.html('<div class="schema-alignment-link-menu-type-search"><input type="text" bind="newBaseUri" size="50"><br/>'+
|
||||||
|
'<button bind="applyButton">Apply</button>' +
|
||||||
|
'<button bind="cancelButton">Cancel</button></div>'
|
||||||
|
);
|
||||||
|
MenuSystem.showMenu(menu,function(){});
|
||||||
|
MenuSystem.positionMenuLeftRight(menu, src);
|
||||||
|
var elmts = DOM.bind(menu);
|
||||||
|
elmts.newBaseUri.val(RdfSchemaAlignment._defaultNamespace).focus().select();
|
||||||
|
elmts.applyButton.click(function() {
|
||||||
|
var newBaseUri = elmts.newBaseUri.val();
|
||||||
|
if(!newBaseUri || !newBaseUri.substring(7)=='http://'){
|
||||||
|
alert('Base URI should start with http://');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MenuSystem.dismissAll();
|
||||||
|
self._replaceBaseUri(newBaseUri);
|
||||||
|
});
|
||||||
|
|
||||||
|
elmts.cancelButton.click(function() {
|
||||||
|
MenuSystem.dismissAll();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
RdfSchemaAlignmentDialog.prototype._replaceBaseUri = function(newBaseUri){
|
||||||
|
var self = this;
|
||||||
|
RdfSchemaAlignment._defaultNamespace = newBaseUri;
|
||||||
|
$.post("/command/save-baseURI?" + $.param({project: theProject.id }),{baseURI:newBaseUri},function(data){
|
||||||
|
if (data.code === "error"){
|
||||||
|
alert('Error:' + data.message)
|
||||||
|
}else{
|
||||||
|
self._baseUriSpan.empty().text(newBaseUri);
|
||||||
|
}
|
||||||
|
},"json");
|
||||||
|
};
|
||||||
|
|
||||||
|
RdfSchemaAlignmentDialog.prototype.getJSON = function() {
|
||||||
|
var rootNodes = [];
|
||||||
|
for (var i = 0; i < this._nodeUIs.length; i++) {
|
||||||
|
var node = this._nodeUIs[i].getJSON();
|
||||||
|
if (node !== null) {
|
||||||
|
rootNodes.push(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
baseUri:RdfSchemaAlignment._defaultNamespace,
|
||||||
|
rootNodes: rootNodes
|
||||||
|
};
|
||||||
|
};
|
83
extensions/rdf-exporter/module/scripts/suggestterm.suggest.js
Executable file
83
extensions/rdf-exporter/module/scripts/suggestterm.suggest.js
Executable file
@ -0,0 +1,83 @@
|
|||||||
|
;(function($) {
|
||||||
|
if (!$.suggest) {
|
||||||
|
alert("$.suggest required");
|
||||||
|
}
|
||||||
|
|
||||||
|
$.suggest("suggestterm",
|
||||||
|
$.extend(true, {}, $.suggest.suggest.prototype, {
|
||||||
|
create_item: function(data,response_data) {
|
||||||
|
var css = this.options.css;
|
||||||
|
|
||||||
|
var li = $("<li>").addClass(css.item);
|
||||||
|
var name = $("<div>").addClass(css.item_name)
|
||||||
|
|
||||||
|
.append($("<label>")
|
||||||
|
.append($.suggest.strongify(data.name,response_data.prefix)));
|
||||||
|
// this converts html escaped strings like "&"
|
||||||
|
// back to "&"
|
||||||
|
data.name = name.text();
|
||||||
|
li.append(name);
|
||||||
|
name.prepend($("<div>").addClass(css.item_type).text(data.id));
|
||||||
|
|
||||||
|
return li;
|
||||||
|
},
|
||||||
|
|
||||||
|
flyout_request:function(data){
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var o = this.options,
|
||||||
|
sug_data = this.flyoutpane.data("data.suggest");
|
||||||
|
if (sug_data && data.id === sug_data.id) {
|
||||||
|
if (!this.flyoutpane.is(":visible")) {
|
||||||
|
var s = this.get_selected();
|
||||||
|
this.flyout_position(s);
|
||||||
|
this.flyoutpane.show();
|
||||||
|
this.input.trigger("fb-flyoutpane-show", this);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check $.suggest.flyout.cache
|
||||||
|
var cached = $.suggest.flyout.cache[data.id];
|
||||||
|
if (cached) {
|
||||||
|
this.flyout_response(cached);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTimeout(this.flyout_request.timeout);
|
||||||
|
this.flyout_request.timeout =
|
||||||
|
setTimeout(function(){self.flyout_response(data);}, o.xhr_delay);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
flyout_response:function(data){
|
||||||
|
var o = this.options,
|
||||||
|
p = this.pane,
|
||||||
|
s = this.get_selected() || [];
|
||||||
|
if (p.is(":visible") && s.length) {
|
||||||
|
var sug_data = s.data("data.suggest");
|
||||||
|
if (sug_data && data.id === sug_data.id) {
|
||||||
|
this.flyoutpane.html('<div class="fbs-flyout-content">' + data.description + '</div>');
|
||||||
|
this.flyout_position(s);
|
||||||
|
this.flyoutpane.show()
|
||||||
|
.data("data.suggest", sug_data);
|
||||||
|
this.input.trigger("fb-flyoutpane-show", this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$.extend($.suggest.suggestterm, {
|
||||||
|
defaults: $.extend(true, {}, $.suggest.suggest.defaults, {
|
||||||
|
service_url: "",
|
||||||
|
service_path: "/command/suggest-term",
|
||||||
|
type_strict:"classes",
|
||||||
|
suggest_new:"Add it"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
})(jQuery);
|
35
extensions/rdf-exporter/module/styles/rdf-schema-alignment-dialog.css
Executable file
35
extensions/rdf-exporter/module/styles/rdf-schema-alignment-dialog.css
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
td.highlighted {
|
||||||
|
background: #e8e8e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.emphasized{
|
||||||
|
font-weight:bold;
|
||||||
|
font-size: 11pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.rdf-schema-alignment-dialog-preview {
|
||||||
|
height: 350px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.rdf-schema-alignment-dialog-canvas {
|
||||||
|
height: 350px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.note{
|
||||||
|
font-size:1em;
|
||||||
|
color: #FF6A00;
|
||||||
|
margin-top:10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.vocabulary-manager-list{
|
||||||
|
height:64%;
|
||||||
|
overflow:auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.vocabulary-manager-footer{
|
||||||
|
height:31%;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.vocabulary-manager-footer h2{
|
||||||
|
margin:0;
|
||||||
|
}
|
39
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/CellBlankNode.java
Executable file
39
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/CellBlankNode.java
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
public class CellBlankNode extends ResourceNode{
|
||||||
|
|
||||||
|
final public int columnIndex;
|
||||||
|
final public String columnName;
|
||||||
|
|
||||||
|
public CellBlankNode(int i,String columnName){
|
||||||
|
this.columnIndex = i;
|
||||||
|
this.columnName = columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource createResource(URI baseUri, Model model, Project project,
|
||||||
|
Row row, int rowIndex,Resource[] blanks) {
|
||||||
|
return model.createResource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeNode(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.key("nodeType");writer.value("cell-as-blank");
|
||||||
|
writer.key("columnIndex");writer.value(columnIndex);
|
||||||
|
writer.key("columnName");writer.value(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
78
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/CellLiteralNode.java
Executable file
78
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/CellLiteralNode.java
Executable file
@ -0,0 +1,78 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
public class CellLiteralNode extends CellNode{
|
||||||
|
|
||||||
|
private String valueType;
|
||||||
|
private String lang;
|
||||||
|
public String getValueType() {
|
||||||
|
return valueType;
|
||||||
|
}
|
||||||
|
public void setValueType(String valueType) {
|
||||||
|
this.valueType = valueType;
|
||||||
|
}
|
||||||
|
public String getLang() {
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
public void setLang(String lang) {
|
||||||
|
this.lang = lang;
|
||||||
|
}
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
writer.key("nodeType");writer.value("cell-as-literal");
|
||||||
|
writer.key("columnIndex");writer.value(columnIndex);
|
||||||
|
writer.key("columnName");writer.value(columnName);
|
||||||
|
if(valueType!=null){
|
||||||
|
writer.key("valueType");writer.value(valueType);
|
||||||
|
}
|
||||||
|
if(lang!=null){
|
||||||
|
writer.key("lang");writer.value(lang);
|
||||||
|
}
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellLiteralNode(int index,String columnName){
|
||||||
|
super(index,columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellLiteralNode(int index,String columnName,String valueType,String lang){
|
||||||
|
this(index,columnName);
|
||||||
|
this.lang = lang;
|
||||||
|
this.valueType = valueType;
|
||||||
|
}
|
||||||
|
public RDFNode createNode(URI baseUri, Model model, Project project,
|
||||||
|
Row row, int rowIndex,Resource[] blanks) {
|
||||||
|
String val;
|
||||||
|
try{
|
||||||
|
val= row.getCell(this.columnIndex).value.toString();
|
||||||
|
}catch(NullPointerException ne){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if(val!=null && val.length()>0){
|
||||||
|
//TODO language and datatype
|
||||||
|
Literal l;
|
||||||
|
if(this.valueType!=null){
|
||||||
|
l = model.createTypedLiteral(val, valueType);
|
||||||
|
}else{
|
||||||
|
l = model.createLiteral(val);
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/CellNode.java
Executable file
12
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/CellNode.java
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
public abstract class CellNode implements Node{
|
||||||
|
final public int columnIndex;
|
||||||
|
final public String columnName;
|
||||||
|
|
||||||
|
public CellNode(int i,String columnName){
|
||||||
|
this.columnIndex = i;
|
||||||
|
this.columnName = columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
80
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/CellResourceNode.java
Executable file
80
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/CellResourceNode.java
Executable file
@ -0,0 +1,80 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.expr.Evaluable;
|
||||||
|
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||||
|
import com.metaweb.gridworks.expr.MetaParser;
|
||||||
|
import com.metaweb.gridworks.model.Cell;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
|
||||||
|
public class CellResourceNode extends ResourceNode{
|
||||||
|
|
||||||
|
private String uriExpression;
|
||||||
|
final public String columnName;
|
||||||
|
public String getUriExpression() {
|
||||||
|
return uriExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final public int columnIndex;
|
||||||
|
|
||||||
|
public CellResourceNode(int i,String columnName){
|
||||||
|
this.columnIndex = i;
|
||||||
|
this.columnName = columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellResourceNode(int columnIndex,String columnName,String exp) {
|
||||||
|
this(columnIndex,columnName);
|
||||||
|
this.uriExpression = exp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource createResource(URI baseUri,Model model,Project project,Row row,int rowIndex,Resource[] blanks) {
|
||||||
|
try{
|
||||||
|
Properties bindings = ExpressionUtils.createBindings(project);
|
||||||
|
Evaluable eval = MetaParser.parse(uriExpression);
|
||||||
|
Cell cell = row.getCell(this.columnIndex);
|
||||||
|
String colName = this.columnIndex>-1?project.columnModel.getColumnByCellIndex(this.columnIndex).getName():"";
|
||||||
|
ExpressionUtils.bind(bindings, row, rowIndex,colName , cell);
|
||||||
|
Object result = eval.evaluate(bindings);
|
||||||
|
if(result.toString().length()>0){
|
||||||
|
String uri = Util.getUri(baseUri, result.toString());
|
||||||
|
Resource r = model.createResource(uri);
|
||||||
|
return r;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
// e.printStackTrace();
|
||||||
|
//an empty cell might result in an exception out of evaluating URI expression... so it is intended to eat the exception
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeNode(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.key("nodeType"); writer.value("cell-as-resource");
|
||||||
|
writer.key("uriExpression"); writer.value(uriExpression);
|
||||||
|
writer.key("columnIndex"); writer.value(columnIndex);
|
||||||
|
if(columnIndex==-1){
|
||||||
|
//Row number
|
||||||
|
writer.key("isRowNumberCell"); writer.value(true);
|
||||||
|
} else {
|
||||||
|
writer.key("columnName"); writer.value(columnName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
33
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/ConstantBlankNode.java
Executable file
33
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/ConstantBlankNode.java
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
public class ConstantBlankNode extends ResourceNode{
|
||||||
|
|
||||||
|
private int _id;
|
||||||
|
ConstantBlankNode(int id){
|
||||||
|
this._id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource createResource(URI baseUri, Model model, Project project,
|
||||||
|
Row row, int rowIndex,Resource[] blanks) {
|
||||||
|
return blanks[this._id];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeNode(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.key("nodeType");writer.value("blank");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
public class ConstantLiteralNode implements Node{
|
||||||
|
|
||||||
|
private String valueType;
|
||||||
|
private String lang;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
|
||||||
|
public ConstantLiteralNode(String val,String type,String l){
|
||||||
|
this.value = val;
|
||||||
|
this.valueType = type;
|
||||||
|
this.lang = l;
|
||||||
|
}
|
||||||
|
public String getValueType() {
|
||||||
|
return valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setValueType(String valueType) {
|
||||||
|
this.valueType = valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getLang() {
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setLang(String lang) {
|
||||||
|
this.lang = lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
writer.key("nodeType"); writer.value("literal");
|
||||||
|
writer.key("value"); writer.value(value);
|
||||||
|
if(valueType!=null){
|
||||||
|
writer.key("valueType");
|
||||||
|
writer.value(valueType);
|
||||||
|
}
|
||||||
|
if(lang!=null){
|
||||||
|
writer.key("lang");
|
||||||
|
writer.value(lang);
|
||||||
|
}
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
public RDFNode createNode(URI baseUri, Model model, Project project,
|
||||||
|
Row row, int rowIndex,Resource[] blanks) {
|
||||||
|
if(this.value!=null && this.value.length()>0){
|
||||||
|
|
||||||
|
Literal l ;
|
||||||
|
if(this.valueType!=null){
|
||||||
|
l = model.createTypedLiteral(this.value, valueType);
|
||||||
|
}else{
|
||||||
|
l = model.createLiteral(this.value);
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
public class ConstantResourceNode extends ResourceNode{
|
||||||
|
|
||||||
|
private String uri;
|
||||||
|
|
||||||
|
|
||||||
|
public String getUri() {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUri(String uri) {
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ConstantResourceNode(String uri){
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource createResource(URI baseUri, Model model, Project project,
|
||||||
|
Row row, int rowIndex,Resource[] blanks) {
|
||||||
|
if(this.uri!=null & this.uri.length()>0){
|
||||||
|
String tmp;
|
||||||
|
try {
|
||||||
|
tmp = Util.getUri(baseUri, this.uri);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Resource r = model.createResource(tmp);
|
||||||
|
return r;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeNode(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.key("nodeType"); writer.value("resource");
|
||||||
|
writer.key("uri"); writer.value(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
36
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/Link.java
Executable file
36
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/Link.java
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.Jsonizable;
|
||||||
|
|
||||||
|
public class Link implements Jsonizable {
|
||||||
|
|
||||||
|
public final String propertyUri;
|
||||||
|
public final String curie;
|
||||||
|
public final Node target;
|
||||||
|
|
||||||
|
public Link(String uri,String curie,Node t){
|
||||||
|
this.propertyUri = uri;
|
||||||
|
this.target = t;
|
||||||
|
this.curie = curie;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
|
||||||
|
writer.object();
|
||||||
|
writer.key("uri");
|
||||||
|
writer.value(propertyUri);
|
||||||
|
writer.key("curie");
|
||||||
|
writer.value(curie);
|
||||||
|
if (target != null) {
|
||||||
|
writer.key("target");
|
||||||
|
target.write(writer, options);
|
||||||
|
}
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
}
|
15
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/Node.java
Executable file
15
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/Node.java
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.Jsonizable;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
public interface Node extends Jsonizable{
|
||||||
|
|
||||||
|
RDFNode createNode(URI baseUri,Model model,Project project,Row row,int rowIndex,Resource[] blanks);
|
||||||
|
}
|
180
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/RdfSchema.java
Executable file
180
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/RdfSchema.java
Executable file
@ -0,0 +1,180 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.model.OverlayModel;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.rdf.ResourceNode.RdfType;
|
||||||
|
|
||||||
|
public class RdfSchema implements OverlayModel {
|
||||||
|
|
||||||
|
final protected List<Node> _rootNodes = new ArrayList<Node>();
|
||||||
|
final protected List<ConstantBlankNode> _blanks = new ArrayList<ConstantBlankNode>();
|
||||||
|
|
||||||
|
public List<ConstantBlankNode> get_blanks() {
|
||||||
|
return _blanks;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected URI baseUri;
|
||||||
|
|
||||||
|
public void setBaseUri(URI baseUri) {
|
||||||
|
this.baseUri = baseUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBaseUri(String base) throws URISyntaxException {
|
||||||
|
this.baseUri = new URI(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RdfSchema() {
|
||||||
|
// FIXME
|
||||||
|
try {
|
||||||
|
this.baseUri = new URI("http://localhost:3333/");
|
||||||
|
} catch (URISyntaxException ue) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI getBaseUri() {
|
||||||
|
return baseUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node getRoot() {
|
||||||
|
return _rootNodes.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public RdfSchema reconstruct(JSONObject o) throws JSONException {
|
||||||
|
RdfSchema s = new RdfSchema();
|
||||||
|
// TODO
|
||||||
|
try {
|
||||||
|
s.baseUri = new URI(o.getString("baseUri"));
|
||||||
|
} catch (URISyntaxException me) {
|
||||||
|
me.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONArray rootNodes = o.getJSONArray("rootNodes");
|
||||||
|
int count = rootNodes.length();
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
JSONObject o2 = rootNodes.getJSONObject(i);
|
||||||
|
Node node = reconstructNode(o2, s);
|
||||||
|
if (node != null) {
|
||||||
|
s._rootNodes.add(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected Node reconstructNode(JSONObject o, RdfSchema s)
|
||||||
|
throws JSONException {
|
||||||
|
Node node = null;
|
||||||
|
int blanksCount = 0;
|
||||||
|
String nodeType = o.getString("nodeType");
|
||||||
|
if (nodeType.startsWith("cell-as-")) {
|
||||||
|
int columnIndex = o.getInt("columnIndex");
|
||||||
|
String columnName = null;
|
||||||
|
if(columnIndex!=-1){
|
||||||
|
columnName = o.getString("columnName");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("cell-as-resource".equals(nodeType)) {
|
||||||
|
String exp = o.getString("uriExpression");
|
||||||
|
node = new CellResourceNode(columnIndex, columnName, exp);
|
||||||
|
if (o.has("rdfTypes")) {
|
||||||
|
List<RdfType> types = reconstructTypes(o
|
||||||
|
.getJSONArray("rdfTypes"));
|
||||||
|
((CellResourceNode) node).setTypes(types);
|
||||||
|
}
|
||||||
|
} else if ("cell-as-literal".equals(nodeType)) {
|
||||||
|
String valueType = o.has("valueType")?Util.getDataType(o.getString("valueType")):null;
|
||||||
|
String lang = o.has("lang") ? o.getString("lang"):null;
|
||||||
|
node = new CellLiteralNode(columnIndex, columnName, valueType, lang);
|
||||||
|
} else if ("cell-as-blank".equals(nodeType)) {
|
||||||
|
node = new CellBlankNode(columnIndex,columnName);
|
||||||
|
if (o.has("rdfTypes")) {
|
||||||
|
List<RdfType> types = reconstructTypes(o
|
||||||
|
.getJSONArray("rdfTypes"));
|
||||||
|
((CellBlankNode) node).setTypes(types);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ("resource".equals(nodeType)) {
|
||||||
|
node = new ConstantResourceNode(o.getString("uri"));
|
||||||
|
if (o.has("rdfTypes")) {
|
||||||
|
List<RdfType> types = reconstructTypes(o
|
||||||
|
.getJSONArray("rdfTypes"));
|
||||||
|
((ConstantResourceNode) node).setTypes(types);
|
||||||
|
}
|
||||||
|
} else if ("literal".equals(nodeType)) {
|
||||||
|
String valueType = o.has("valueType")?Util.getDataType(o.getString("valueType")):null;
|
||||||
|
String lang = o.has("lang") ? o.getString("lang"):null;
|
||||||
|
node = new ConstantLiteralNode(o.getString("value"), valueType,lang);
|
||||||
|
} else if ("blank".equals(nodeType)) {
|
||||||
|
node = new ConstantBlankNode(blanksCount);
|
||||||
|
blanksCount += 1;
|
||||||
|
s._blanks.add((ConstantBlankNode) node);
|
||||||
|
if (o.has("rdfTypes")) {
|
||||||
|
List<RdfType> types = reconstructTypes(o
|
||||||
|
.getJSONArray("rdfTypes"));
|
||||||
|
((ConstantBlankNode) node).setTypes(types);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node != null && node instanceof ResourceNode && o.has("links")) {
|
||||||
|
ResourceNode node2 = (ResourceNode) node;
|
||||||
|
|
||||||
|
JSONArray links = o.getJSONArray("links");
|
||||||
|
int linkCount = links.length();
|
||||||
|
|
||||||
|
for (int j = 0; j < linkCount; j++) {
|
||||||
|
JSONObject oLink = links.getJSONObject(j);
|
||||||
|
|
||||||
|
node2.addLink(new Link(oLink.getString("uri"), oLink.getString("curie"),oLink
|
||||||
|
.has("target")
|
||||||
|
&& !oLink.isNull("target") ? reconstructNode(oLink
|
||||||
|
.getJSONObject("target"), s) : null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
static private List<RdfType> reconstructTypes(JSONArray arr)
|
||||||
|
throws JSONException {
|
||||||
|
List<RdfType> lst = new ArrayList<RdfType>();
|
||||||
|
for (int i = 0; i < arr.length(); i++) {
|
||||||
|
String uri = arr.getJSONObject(i).getString("uri");
|
||||||
|
String curie = arr.getJSONObject(i).getString("curie");
|
||||||
|
lst.add(new RdfType(uri, curie));
|
||||||
|
}
|
||||||
|
return lst;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
writer.key("baseUri"); writer.value(baseUri);
|
||||||
|
|
||||||
|
writer.key("rootNodes");
|
||||||
|
writer.array();
|
||||||
|
|
||||||
|
for (Node node : _rootNodes) {
|
||||||
|
node.write(writer, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.endArray();
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public RdfSchema load(Project project, JSONObject obj) throws Exception {
|
||||||
|
return reconstruct(obj);
|
||||||
|
}
|
||||||
|
}
|
133
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/ResourceNode.java
Executable file
133
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/ResourceNode.java
Executable file
@ -0,0 +1,133 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
|
||||||
|
|
||||||
|
abstract public class ResourceNode implements Node {
|
||||||
|
|
||||||
|
private List<Link> links = new ArrayList<Link>();
|
||||||
|
|
||||||
|
private List<RdfType> rdfTypes = new ArrayList<RdfType>();
|
||||||
|
|
||||||
|
public void addLink(Link link) {
|
||||||
|
this.links.add(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addType(RdfType type) {
|
||||||
|
this.rdfTypes.add(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Link getLink(int index) {
|
||||||
|
return this.links.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLinkCount() {
|
||||||
|
return this.links.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RdfType> getTypes() {
|
||||||
|
return this.rdfTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void writeNode(JSONWriter writer, Properties options) throws JSONException;
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
//writer node
|
||||||
|
writeNode(writer,options);
|
||||||
|
//write types
|
||||||
|
writer.key("rdfTypes");
|
||||||
|
writer.array();
|
||||||
|
for(RdfType type:this.getTypes()){
|
||||||
|
writer.object();
|
||||||
|
writer.key("uri");writer.value(type.uri);
|
||||||
|
writer.key("curie");writer.value(type.curie);
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
writer.endArray();
|
||||||
|
//write links
|
||||||
|
writer.key("links");
|
||||||
|
writer.array();
|
||||||
|
for(int i=0;i<getLinkCount();i++){
|
||||||
|
Link l = getLink(i);
|
||||||
|
/*writer.object();
|
||||||
|
writer.key("uri");writer.value(l.propertyUri);
|
||||||
|
writer.key("target");
|
||||||
|
l.target.write(writer, options);
|
||||||
|
writer.endObject();*/
|
||||||
|
|
||||||
|
l.write(writer, options);
|
||||||
|
}
|
||||||
|
writer.endArray();
|
||||||
|
|
||||||
|
writer.endObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void addTypes(Resource r,Model model){
|
||||||
|
for(RdfType type:this.getTypes()){
|
||||||
|
r.addProperty(RDF.type, model.createResource(type.uri));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Resource addLinks(Resource r,URI baseUri,Model model,Project project,Row row,int rowIndex,Resource[] blanks){
|
||||||
|
for(int i=0;i<getLinkCount();i++){
|
||||||
|
Link l = getLink(i);
|
||||||
|
String propertyUri;
|
||||||
|
try {
|
||||||
|
propertyUri = Util.getUri(baseUri, l.propertyUri);
|
||||||
|
Property p = model.createProperty(propertyUri);
|
||||||
|
RDFNode o = l.target.createNode(baseUri, model, project, row, rowIndex,blanks);
|
||||||
|
if(o!=null){
|
||||||
|
r.addProperty(p, o);
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTypes(List<RdfType> types) {
|
||||||
|
this.rdfTypes = types;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RDFNode createNode(URI baseUri,Model model,Project project,Row row,int rowIndex,Resource[] blanks) {
|
||||||
|
Resource r = createResource(baseUri, model, project, row, rowIndex,blanks);
|
||||||
|
if(r==null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
addTypes(r, model);
|
||||||
|
return addLinks(r,baseUri,model,project,row,rowIndex,blanks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Resource createResource(URI baseUri,Model model,Project project,Row row,int rowIndex,Resource[] blanks) ;
|
||||||
|
|
||||||
|
public static class RdfType{
|
||||||
|
String uri;
|
||||||
|
String curie;
|
||||||
|
public RdfType(String uri,String curie){
|
||||||
|
this.uri = uri;
|
||||||
|
this.curie = curie;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/Util.java
Executable file
47
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/Util.java
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
package com.metaweb.gridworks.rdf;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
|
||||||
|
private static final String XSD_INT_URI ="http://www.w3.org/2001/XMLSchema#int";
|
||||||
|
private static final String XSD_DOUBLE_URI ="http://www.w3.org/2001/XMLSchema#double";
|
||||||
|
private static final String XSD_DATE_URI ="http://www.w3.org/2001/XMLSchema#date";
|
||||||
|
|
||||||
|
public static String getUri(URI base,String rel)throws URISyntaxException{
|
||||||
|
return base.resolve(rel).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDataType(String s){
|
||||||
|
if(s==null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if(s.equals(XSD_INT_URI)){
|
||||||
|
return XSD_INT_URI;
|
||||||
|
}
|
||||||
|
if(s.equals(XSD_DOUBLE_URI)){
|
||||||
|
return XSD_DOUBLE_URI;
|
||||||
|
}
|
||||||
|
if(s.equals(XSD_DATE_URI)){
|
||||||
|
return XSD_DATE_URI;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RdfSchema getProjectSchema(Project project) {
|
||||||
|
synchronized (project) {
|
||||||
|
RdfSchema rdfSchema = (RdfSchema) project.overlayModels.get("rdfSchema");
|
||||||
|
if (rdfSchema == null) {
|
||||||
|
rdfSchema = new RdfSchema();
|
||||||
|
|
||||||
|
project.overlayModels.put("rdfSchema", rdfSchema);
|
||||||
|
project.getMetadata().updateModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rdfSchema;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.Jsonizable;
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.rdf.vocab.VocabularyManager;
|
||||||
|
|
||||||
|
public class DeleteVocabularyCommand extends Command{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
String uri = request.getParameter("uri");
|
||||||
|
try {
|
||||||
|
VocabularyManager.singleton.deleteVocabulary(uri);
|
||||||
|
respondJSON(response, new Jsonizable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
writer.key("code"); writer.value("ok");
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (JSONException e) {
|
||||||
|
respondException(response, e);
|
||||||
|
} catch (Exception e){
|
||||||
|
respondException(response, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.Jsonizable;
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.rdf.vocab.VocabularyExistException;
|
||||||
|
import com.metaweb.gridworks.rdf.vocab.VocabularyManager;
|
||||||
|
|
||||||
|
public class ImportVocabularyCommand extends Command{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
String prefix = request.getParameter("prefix");
|
||||||
|
String url = request.getParameter("url");
|
||||||
|
String namespace = request.getParameter("namespace");
|
||||||
|
try {
|
||||||
|
VocabularyManager.singleton.addVocabulary(url, prefix, namespace);
|
||||||
|
respondJSON(response, new Jsonizable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
writer.key("code"); writer.value("ok");
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (JSONException e) {
|
||||||
|
respondException(response, e);
|
||||||
|
} catch (VocabularyExistException e) {
|
||||||
|
respondException(response, e);
|
||||||
|
} catch (Exception e){
|
||||||
|
respondException(response, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.rdf.vocab.Vocabulary;
|
||||||
|
import com.metaweb.gridworks.rdf.vocab.VocabularyManager;
|
||||||
|
|
||||||
|
public class ListVocabulariesCommand extends Command{
|
||||||
|
@Override
|
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
try{
|
||||||
|
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||||
|
writer.object();
|
||||||
|
writer.key("vocabularies");
|
||||||
|
writer.array();
|
||||||
|
Properties p = new Properties();
|
||||||
|
for(Vocabulary v:VocabularyManager.singleton.getVocabularies()){
|
||||||
|
v.write(writer, p);
|
||||||
|
}
|
||||||
|
writer.endArray();
|
||||||
|
writer.endObject();
|
||||||
|
} catch (Exception e) {
|
||||||
|
respondException(response, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
import com.metaweb.gridworks.rdf.ConstantBlankNode;
|
||||||
|
import com.metaweb.gridworks.rdf.Node;
|
||||||
|
import com.metaweb.gridworks.rdf.RdfSchema;
|
||||||
|
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||||
|
|
||||||
|
public class PreviewRdfCommand extends Command {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
try {
|
||||||
|
Project project = getProject(request);
|
||||||
|
Engine engine = getEngine(request, project);
|
||||||
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
|
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
String jsonString = request.getParameter("schema");
|
||||||
|
JSONObject json = ParsingUtilities.evaluateJsonStringToObject(jsonString);
|
||||||
|
RdfSchema schema = RdfSchema.reconstruct(json);
|
||||||
|
|
||||||
|
Model model = ModelFactory.createDefaultModel();
|
||||||
|
URI baseUri = schema.getBaseUri();
|
||||||
|
Node root = schema.getRoot();
|
||||||
|
|
||||||
|
Resource[] blanks = new Resource[schema.get_blanks().size()];
|
||||||
|
int i=0;
|
||||||
|
for (ConstantBlankNode b : schema.get_blanks()){
|
||||||
|
blanks[i] = model.createResource();
|
||||||
|
i +=1;
|
||||||
|
}
|
||||||
|
RowVisitor visitor = new RdfRowVisitor(model, baseUri, root,blanks,20);
|
||||||
|
|
||||||
|
filteredRows.accept(project, visitor);
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
model.write(sw,"N3");
|
||||||
|
|
||||||
|
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||||
|
writer.object();
|
||||||
|
writer.key("v");
|
||||||
|
writer.value(sw.getBuffer().toString());
|
||||||
|
writer.endObject();
|
||||||
|
//respond(response, "{v:" + sw.getBuffer().toString() + "}");
|
||||||
|
}catch (Exception e) {
|
||||||
|
respondException(response, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static class RdfRowVisitor implements RowVisitor{
|
||||||
|
Model model;
|
||||||
|
URI base;
|
||||||
|
Node root;
|
||||||
|
Resource[] blanks;
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
int _count;
|
||||||
|
public RdfRowVisitor(Model m,URI base, Node root,Resource[] blanks,int l){
|
||||||
|
this.model = m;
|
||||||
|
this.base = base;
|
||||||
|
this.root = root;
|
||||||
|
this.blanks = blanks;
|
||||||
|
this.limit = l;
|
||||||
|
}
|
||||||
|
public void end(Project project) {
|
||||||
|
// do nothing
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(Project project) {
|
||||||
|
// do nothing
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
|
if(_count>=limit){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
root.createNode(base, model, project, row, rowIndex,blanks);
|
||||||
|
_count +=1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.rdf.Util;
|
||||||
|
|
||||||
|
public class SaveBaseURI extends Command {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
try {
|
||||||
|
Project project = getProject(request);
|
||||||
|
String base = request.getParameter("baseURI");
|
||||||
|
|
||||||
|
Util.getProjectSchema(project).setBaseUri(base);
|
||||||
|
|
||||||
|
project.getMetadata().updateModified();
|
||||||
|
|
||||||
|
respond(response,"OK","");
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
respondException(response, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.process.Process;
|
||||||
|
import com.metaweb.gridworks.rdf.RdfSchema;
|
||||||
|
import com.metaweb.gridworks.rdf.operations.SaveRdfSchemaOperation;
|
||||||
|
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||||
|
|
||||||
|
public class SaveRdfSchemaCommand extends Command{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Project project = getProject(request);
|
||||||
|
|
||||||
|
String jsonString = request.getParameter("schema");
|
||||||
|
JSONObject json = ParsingUtilities.evaluateJsonStringToObject(jsonString);
|
||||||
|
RdfSchema schema = RdfSchema.reconstruct(json);
|
||||||
|
|
||||||
|
AbstractOperation op = new SaveRdfSchemaOperation(schema);
|
||||||
|
Process process = op.createProcess(project, new Properties());
|
||||||
|
|
||||||
|
performProcessAndRespond(request, response, project, process);
|
||||||
|
|
||||||
|
/*project.schema = schema;
|
||||||
|
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
Writer w = response.getWriter();
|
||||||
|
JSONWriter writer = new JSONWriter(w);
|
||||||
|
writer.object();
|
||||||
|
writer.key("code"); writer.value("ok");
|
||||||
|
writer.key("historyEntry");
|
||||||
|
|
||||||
|
//dummy history for now
|
||||||
|
writer.object();
|
||||||
|
writer.key("op"); writer.value("saveRdfSchema");
|
||||||
|
writer.key("description"); writer.value("Save RDF schema");
|
||||||
|
writer.endObject();
|
||||||
|
|
||||||
|
writer.endObject();
|
||||||
|
|
||||||
|
w.flush();
|
||||||
|
w.close();*/
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
respondException(response, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.Jsonizable;
|
||||||
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.rdf.vocab.RDFNode;
|
||||||
|
import com.metaweb.gridworks.rdf.vocab.VocabularyManager;
|
||||||
|
|
||||||
|
public class SuggestTermCommand extends Command{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
|
||||||
|
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||||
|
|
||||||
|
String type = request.getParameter("type_strict");
|
||||||
|
|
||||||
|
String prefix = request.getParameter("prefix");
|
||||||
|
try{
|
||||||
|
writer.object();
|
||||||
|
|
||||||
|
writer.key("prefix");
|
||||||
|
writer.value(prefix);
|
||||||
|
|
||||||
|
writer.key("result");
|
||||||
|
writer.array();
|
||||||
|
List<RDFNode> nodes;
|
||||||
|
if(type!=null && type.trim().equals("property")){
|
||||||
|
nodes = VocabularyManager.singleton.searchProperties(prefix);
|
||||||
|
}else{
|
||||||
|
nodes = VocabularyManager.singleton.searchClasses(prefix);
|
||||||
|
}
|
||||||
|
for(RDFNode c:nodes){
|
||||||
|
c.writeAsSearchResult(writer);
|
||||||
|
}
|
||||||
|
writer.endArray();
|
||||||
|
writer.endObject();
|
||||||
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new ServletException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Result implements Jsonizable{
|
||||||
|
|
||||||
|
private List<String[]> results = new ArrayList<String[]>();
|
||||||
|
private String prefix;
|
||||||
|
|
||||||
|
Result(String p){
|
||||||
|
this.prefix = p;
|
||||||
|
}
|
||||||
|
void addResult(String id, String name){
|
||||||
|
String[] res = new String[] {id,name};
|
||||||
|
results.add(res);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
|
||||||
|
|
||||||
|
writer.key("prefix");
|
||||||
|
writer.value(prefix);
|
||||||
|
|
||||||
|
writer.key("result");
|
||||||
|
writer.array();
|
||||||
|
for(String[] res:results){
|
||||||
|
writer.object();
|
||||||
|
|
||||||
|
writer.key("id");
|
||||||
|
writer.value(res[0]);
|
||||||
|
|
||||||
|
writer.key("name");
|
||||||
|
writer.value(res[1]);
|
||||||
|
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
writer.endArray();
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
111
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/exporters/RdfExporter.java
Executable file
111
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/exporters/RdfExporter.java
Executable file
@ -0,0 +1,111 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.exporters;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
|
import com.metaweb.gridworks.exporters.Exporter;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
import com.metaweb.gridworks.rdf.ConstantBlankNode;
|
||||||
|
import com.metaweb.gridworks.rdf.Node;
|
||||||
|
import com.metaweb.gridworks.rdf.RdfSchema;
|
||||||
|
import com.metaweb.gridworks.rdf.Util;
|
||||||
|
|
||||||
|
public class RdfExporter implements Exporter{
|
||||||
|
|
||||||
|
private String format;
|
||||||
|
|
||||||
|
public RdfExporter(String f){
|
||||||
|
this.format = f;
|
||||||
|
}
|
||||||
|
public void export(Project project, Properties options, Engine engine,
|
||||||
|
OutputStream outputStream) throws IOException {
|
||||||
|
|
||||||
|
RdfSchema schema = Util.getProjectSchema(project);
|
||||||
|
Model model = ModelFactory.createDefaultModel();
|
||||||
|
URI baseUri = schema.getBaseUri();
|
||||||
|
Node root = schema.getRoot();
|
||||||
|
|
||||||
|
Resource[] blanks = new Resource[schema.get_blanks().size()];
|
||||||
|
int i=0;
|
||||||
|
for (ConstantBlankNode b : schema.get_blanks()){
|
||||||
|
blanks[i] = model.createResource();
|
||||||
|
i +=1;
|
||||||
|
}
|
||||||
|
RowVisitor visitor = new RdfRowVisitor(model, baseUri, root,blanks);
|
||||||
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
|
filteredRows.accept(project, visitor);
|
||||||
|
model.write(outputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void export(Project project, Properties options, Engine engine,
|
||||||
|
Writer writer) throws IOException {
|
||||||
|
RdfSchema schema = Util.getProjectSchema(project);
|
||||||
|
Model model = ModelFactory.createDefaultModel();
|
||||||
|
URI baseUri = schema.getBaseUri();
|
||||||
|
Node root = schema.getRoot();
|
||||||
|
|
||||||
|
Resource[] blanks = new Resource[schema.get_blanks().size()];
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (ConstantBlankNode b : schema.get_blanks()){
|
||||||
|
blanks[i] = model.createResource();
|
||||||
|
i +=1;
|
||||||
|
}
|
||||||
|
RowVisitor visitor = new RdfRowVisitor(model, baseUri, root,blanks);
|
||||||
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
|
filteredRows.accept(project, visitor);
|
||||||
|
model.write(writer,format);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContentType() {
|
||||||
|
if(format.equals("N3")){
|
||||||
|
return "text/rdf+n3";
|
||||||
|
}else{
|
||||||
|
return "application/rdf+xml";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean takeWriter() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class RdfRowVisitor implements RowVisitor{
|
||||||
|
Model model;
|
||||||
|
URI base;
|
||||||
|
Node root;
|
||||||
|
Resource[] blanks;
|
||||||
|
public RdfRowVisitor(Model m,URI base, Node root,Resource[] blanks){
|
||||||
|
this.model = m;
|
||||||
|
this.base = base;
|
||||||
|
this.root = root;
|
||||||
|
this.blanks = blanks;
|
||||||
|
}
|
||||||
|
public void end(Project project) {
|
||||||
|
// do nothing
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(Project project) {
|
||||||
|
// do nothing
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
|
root.createNode(base, model, project, row, rowIndex,blanks);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.expr;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.expr.Binder;
|
||||||
|
import com.metaweb.gridworks.model.Cell;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.model.Row;
|
||||||
|
import com.metaweb.gridworks.rdf.Util;
|
||||||
|
|
||||||
|
public class RdfBinder implements Binder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bind(Properties bindings, Row row, int rowIndex, String columnName, Cell cell) {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeBindings(Properties bindings, Project project) {
|
||||||
|
bindings.put("baseURI", Util.getProjectSchema(project).getBaseUri());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.expr.functions.strings;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.expr.EvalError;
|
||||||
|
import com.metaweb.gridworks.gel.ControlFunctionRegistry;
|
||||||
|
import com.metaweb.gridworks.gel.Function;
|
||||||
|
|
||||||
|
public class Urlify implements Function {
|
||||||
|
|
||||||
|
public Object call(Properties bindings, Object[] args) {
|
||||||
|
if(args.length==1 || args.length==2){
|
||||||
|
String s = args[0].toString();
|
||||||
|
s = s.replaceAll("\\s+", "_");
|
||||||
|
if(args.length==2){
|
||||||
|
String base = args[1].toString();
|
||||||
|
URI base_uri;
|
||||||
|
try {
|
||||||
|
base_uri = new URI(base);
|
||||||
|
return base_uri.resolve(s).toString();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " unable to encode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return URLEncoder.encode(s, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " unable to encode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 1 string");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
writer.key("description"); writer.value("replaces spaces with underscore");
|
||||||
|
writer.key("params"); writer.value("string s");
|
||||||
|
writer.key("returns"); writer.value("string");
|
||||||
|
writer.endObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,137 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.operations;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.LineNumberReader;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.history.Change;
|
||||||
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.operations.OperationRegistry;
|
||||||
|
import com.metaweb.gridworks.rdf.RdfSchema;
|
||||||
|
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||||
|
import com.metaweb.gridworks.util.Pool;
|
||||||
|
|
||||||
|
public class SaveRdfSchemaOperation extends AbstractOperation {
|
||||||
|
|
||||||
|
final protected RdfSchema _schema;
|
||||||
|
|
||||||
|
public SaveRdfSchemaOperation(RdfSchema schema) {
|
||||||
|
this._schema = schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public AbstractOperation reconstruct(Project project, JSONObject obj)
|
||||||
|
throws Exception {
|
||||||
|
return new SaveRdfSchemaOperation(RdfSchema.reconstruct(obj
|
||||||
|
.getJSONObject("schema")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
writer.key("op");
|
||||||
|
writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
|
writer.key("description");
|
||||||
|
writer.value("Save RDF schema skeleton");
|
||||||
|
writer.key("schema");
|
||||||
|
_schema.write(writer, options);
|
||||||
|
writer.endObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getBriefDescription(Project project) {
|
||||||
|
return "Save RDF schema skelton";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HistoryEntry createHistoryEntry(Project project,
|
||||||
|
long historyEntryID) throws Exception {
|
||||||
|
String description = "Save RDF schema skeleton";
|
||||||
|
|
||||||
|
Change change = new RdfSchemaChange(_schema);
|
||||||
|
|
||||||
|
return new HistoryEntry(historyEntryID, project, description,
|
||||||
|
SaveRdfSchemaOperation.this, change);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public class RdfSchemaChange implements Change {
|
||||||
|
final protected RdfSchema _newSchema;
|
||||||
|
protected RdfSchema _oldSchema;
|
||||||
|
|
||||||
|
public RdfSchemaChange(RdfSchema schema) {
|
||||||
|
_newSchema = schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply(Project project) {
|
||||||
|
synchronized (project) {
|
||||||
|
_oldSchema = (RdfSchema) project.overlayModels.get("rdfSchema");
|
||||||
|
project.overlayModels.put("rdfSchema", _newSchema);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void revert(Project project) {
|
||||||
|
synchronized (project) {
|
||||||
|
if (_oldSchema == null) {
|
||||||
|
project.overlayModels.remove("rdfSchema");
|
||||||
|
} else {
|
||||||
|
project.overlayModels.put("rdfSchema", _oldSchema);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(Writer writer, Properties options) throws IOException {
|
||||||
|
writer.write("newSchema=");
|
||||||
|
writeRdfSchema(_newSchema, writer);
|
||||||
|
writer.write('\n');
|
||||||
|
writer.write("oldSchema=");
|
||||||
|
writeRdfSchema(_oldSchema, writer);
|
||||||
|
writer.write('\n');
|
||||||
|
writer.write("/ec/\n"); // end of change marker
|
||||||
|
}
|
||||||
|
|
||||||
|
static public Change load(LineNumberReader reader, Pool pool)
|
||||||
|
throws Exception {
|
||||||
|
RdfSchema oldSchema = null;
|
||||||
|
RdfSchema newSchema = null;
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null && !"/ec/".equals(line)) {
|
||||||
|
int equal = line.indexOf('=');
|
||||||
|
CharSequence field = line.subSequence(0, equal);
|
||||||
|
String value = line.substring(equal + 1);
|
||||||
|
|
||||||
|
if ("oldSchema".equals(field) && value.length() > 0) {
|
||||||
|
oldSchema = RdfSchema.reconstruct(ParsingUtilities
|
||||||
|
.evaluateJsonStringToObject(value));
|
||||||
|
} else if ("newSchema".equals(field) && value.length() > 0) {
|
||||||
|
newSchema = RdfSchema.reconstruct(ParsingUtilities
|
||||||
|
.evaluateJsonStringToObject(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RdfSchemaChange change = new RdfSchemaChange(newSchema);
|
||||||
|
change._oldSchema = oldSchema;
|
||||||
|
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected void writeRdfSchema(RdfSchema s, Writer writer)
|
||||||
|
throws IOException {
|
||||||
|
if (s != null) {
|
||||||
|
JSONWriter jsonWriter = new JSONWriter(writer);
|
||||||
|
try {
|
||||||
|
s.write(jsonWriter, new Properties());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
130
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/vocab/RDFNode.java
Executable file
130
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/vocab/RDFNode.java
Executable file
@ -0,0 +1,130 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.vocab;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.Jsonizable;
|
||||||
|
|
||||||
|
public abstract class RDFNode implements Jsonizable{
|
||||||
|
private String preferredCURIE;
|
||||||
|
private String description;
|
||||||
|
private String URI;
|
||||||
|
private String label;
|
||||||
|
private String vocabularyPrefix;
|
||||||
|
private String vocabularyUri;
|
||||||
|
|
||||||
|
public String getVocabularyUri() {
|
||||||
|
return vocabularyUri;
|
||||||
|
}
|
||||||
|
public void setVocabularyUri(String vocabularyUri) {
|
||||||
|
this.vocabularyUri = vocabularyUri;
|
||||||
|
}
|
||||||
|
public String getVocabularyPrefix() {
|
||||||
|
return vocabularyPrefix;
|
||||||
|
}
|
||||||
|
public void setVocabularyPrefix(String vocabularyPrefix) {
|
||||||
|
this.vocabularyPrefix = vocabularyPrefix;
|
||||||
|
}
|
||||||
|
public String getPreferredCURIE() {
|
||||||
|
return preferredCURIE;
|
||||||
|
}
|
||||||
|
public void setPreferredCURIE(String preferredCURIE) {
|
||||||
|
this.preferredCURIE = preferredCURIE;
|
||||||
|
}
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
public String getURI() {
|
||||||
|
return URI;
|
||||||
|
}
|
||||||
|
public void setURI(String uRI) {
|
||||||
|
URI = uRI;
|
||||||
|
}
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
public RDFNode(){
|
||||||
|
|
||||||
|
}
|
||||||
|
public RDFNode(String description, String uRI,
|
||||||
|
String label,String prefix,String vocabularyUri) {
|
||||||
|
this.description = description;
|
||||||
|
URI = uRI;
|
||||||
|
this.label = label;
|
||||||
|
this.vocabularyPrefix = prefix;
|
||||||
|
this.preferredCURIE = composePreferredCurie();
|
||||||
|
this.vocabularyUri = vocabularyUri;
|
||||||
|
}
|
||||||
|
private String composePreferredCurie(){
|
||||||
|
String qname;
|
||||||
|
if(this.URI==null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if(this.URI.indexOf("#")!=-1){
|
||||||
|
qname = this.URI.substring(this.URI.indexOf("#")+1);
|
||||||
|
}else{
|
||||||
|
qname = this.URI.substring(this.URI.lastIndexOf("/")+1);
|
||||||
|
}
|
||||||
|
return this.vocabularyPrefix + ":" + qname;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract String getType();
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
|
||||||
|
writer.key("type");
|
||||||
|
writer.value(this.getType());
|
||||||
|
writer.key("prefix");
|
||||||
|
writer.value(vocabularyPrefix);
|
||||||
|
writer.key("preferredCURIE");
|
||||||
|
writer.value(this.preferredCURIE);
|
||||||
|
writer.key("label");
|
||||||
|
writer.value(label);
|
||||||
|
writer.key("description");
|
||||||
|
writer.value(description);
|
||||||
|
writer.key("URI");
|
||||||
|
writer.value(URI);
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeAsSearchResult(JSONWriter writer)throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
|
||||||
|
writer.key("id");
|
||||||
|
writer.value(URI);
|
||||||
|
|
||||||
|
writer.key("name");
|
||||||
|
writer.value(preferredCURIE);
|
||||||
|
|
||||||
|
writer.key("description");
|
||||||
|
writer.value(description);
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(!(obj instanceof RDFNode)) return false;
|
||||||
|
RDFNode n = (RDFNode) obj;
|
||||||
|
if(n.getURI()==null || this.URI==null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.URI.equals(n.getURI());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return this.URI.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
16
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/vocab/RDFSClass.java
Executable file
16
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/vocab/RDFSClass.java
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.vocab;
|
||||||
|
|
||||||
|
|
||||||
|
public class RDFSClass extends RDFNode{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "class";
|
||||||
|
}
|
||||||
|
|
||||||
|
public RDFSClass( String uRI,
|
||||||
|
String label,String description,String prefix,String vocabularyUri) {
|
||||||
|
super(description,uRI,label,prefix,vocabularyUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.vocab;
|
||||||
|
|
||||||
|
|
||||||
|
public class RDFSProperty extends RDFNode{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "property";
|
||||||
|
}
|
||||||
|
public RDFSProperty(String uRI,
|
||||||
|
String label,String description,String prefix,String vocabularyUri) {
|
||||||
|
super(description,uRI,label,prefix,vocabularyUri);
|
||||||
|
}
|
||||||
|
}
|
65
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/vocab/Vocabulary.java
Executable file
65
extensions/rdf-exporter/src/com/metaweb/gridworks/rdf/vocab/Vocabulary.java
Executable file
@ -0,0 +1,65 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.vocab;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.Jsonizable;
|
||||||
|
|
||||||
|
public class Vocabulary implements Jsonizable{
|
||||||
|
private final String name;
|
||||||
|
private final String uri;
|
||||||
|
private List<RDFSClass> classes = new ArrayList<RDFSClass>();
|
||||||
|
private List<RDFSProperty> properties = new ArrayList<RDFSProperty>();
|
||||||
|
|
||||||
|
public Vocabulary(String name,String uri){
|
||||||
|
this.name = name;
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addClass(RDFSClass clazz){
|
||||||
|
this.classes.add(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addProperty(RDFSProperty prop){
|
||||||
|
this.properties.add(prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RDFSClass> getClasses() {
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClasses(List<RDFSClass> classes) {
|
||||||
|
this.classes = classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RDFSProperty> getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(List<RDFSProperty> properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUri() {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
|
||||||
|
writer.key("name"); writer.value(name);
|
||||||
|
writer.key("uri"); writer.value(uri);
|
||||||
|
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.vocab;
|
||||||
|
|
||||||
|
public class VocabularyExistException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1916094460059608851L;
|
||||||
|
|
||||||
|
public VocabularyExistException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,119 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.vocab;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
|
import com.hp.hpl.jena.query.Query;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
|
||||||
|
public class VocabularyImporter {
|
||||||
|
|
||||||
|
private static final String PREFIXES = "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> " +
|
||||||
|
"PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
|
||||||
|
"PREFIX skos:<http://www.w3.org/2004/02/skos/core#> ";
|
||||||
|
private static final String CLASSES_QUERY_P1 = PREFIXES +
|
||||||
|
"SELECT ?resource ?label ?en_label ?description ?en_description ?definition ?en_definition " +
|
||||||
|
"WHERE { " +
|
||||||
|
"?resource rdf:type rdfs:Class. " +
|
||||||
|
"OPTIONAL {?resource rdfs:label ?label.} " +
|
||||||
|
"OPTIONAL {?resource rdfs:label ?en_label. FILTER langMatches( lang(?en_label), \"EN\" ) } " +
|
||||||
|
"OPTIONAL {?resource rdfs:comment ?description.} " +
|
||||||
|
"OPTIONAL {?resource rdfs:comment ?en_description. FILTER langMatches( lang(?en_description), \"EN\" ) } " +
|
||||||
|
"OPTIONAL {?resource skos:definition ?definition.} " +
|
||||||
|
"OPTIONAL {?resource skos:definition ?en_definition. FILTER langMatches( lang(?en_definition), \"EN\" ) } " +
|
||||||
|
"FILTER regex(str(?resource), \"^";
|
||||||
|
private static final String CLASSES_QUERY_P2 = "\")}";
|
||||||
|
|
||||||
|
private static final String PROPERTIES_QUERY_P1 = PREFIXES +
|
||||||
|
"SELECT ?resource ?label ?en_label ?description ?en_description ?definition ?en_definition " +
|
||||||
|
"WHERE { " +
|
||||||
|
"?resource rdf:type rdf:Property. " +
|
||||||
|
"OPTIONAL {?resource rdfs:label ?label.} " +
|
||||||
|
"OPTIONAL {?resource rdfs:label ?en_label. FILTER langMatches( lang(?en_label), \"EN\" ) } " +
|
||||||
|
"OPTIONAL {?resource rdfs:comment ?description.} " +
|
||||||
|
"OPTIONAL {?resource rdfs:comment ?en_description. FILTER langMatches( lang(?en_description), \"EN\" ) } " +
|
||||||
|
"OPTIONAL {?resource skos:definition ?definition.} " +
|
||||||
|
"OPTIONAL {?resource skos:definition ?en_definition. FILTER langMatches( lang(?en_definition), \"EN\" ) } " +
|
||||||
|
"FILTER regex(str(?resource), \"^";
|
||||||
|
private static final String PROPERTIES_QUERY_P2 = "\")}";
|
||||||
|
|
||||||
|
public Vocabulary getVocabulary(String url, String prefix, String namespace, String format){
|
||||||
|
Model m = getModel(url, format);
|
||||||
|
return getVocabulary(m,namespace,prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Model getModel(String url,String format){
|
||||||
|
Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);//ModelFactory.createDefaultModel();
|
||||||
|
model.read(url);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Vocabulary getVocabulary(Model m, String namespace, String prefix){
|
||||||
|
Query query = QueryFactory.create(CLASSES_QUERY_P1 + namespace.trim() + CLASSES_QUERY_P2);
|
||||||
|
QueryExecution qe = QueryExecutionFactory.create(query, m);
|
||||||
|
ResultSet res = qe.execSelect();
|
||||||
|
Set<String> seen = new HashSet<String>();
|
||||||
|
Vocabulary vocab = new Vocabulary(prefix, namespace);
|
||||||
|
while(res.hasNext()){
|
||||||
|
QuerySolution qs = res.nextSolution();
|
||||||
|
String uri = qs.getResource("resource").getURI();
|
||||||
|
if(seen.contains(uri)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String label = getFirstNotNull(new Literal[]{qs.getLiteral("en_label"),qs.getLiteral("label")});
|
||||||
|
|
||||||
|
String description = getFirstNotNull(new Literal[]{qs.getLiteral("en_definition"),qs.getLiteral("definition"),
|
||||||
|
qs.getLiteral("en_description"),qs.getLiteral("description")}) ;
|
||||||
|
RDFSClass clazz = new RDFSClass(uri, label, description,prefix,namespace);
|
||||||
|
vocab.addClass(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
query = QueryFactory.create(PROPERTIES_QUERY_P1 + namespace.trim() + PROPERTIES_QUERY_P2);
|
||||||
|
qe = QueryExecutionFactory.create(query, m);
|
||||||
|
res = qe.execSelect();
|
||||||
|
seen = new HashSet<String>();
|
||||||
|
while(res.hasNext()){
|
||||||
|
QuerySolution qs = res.nextSolution();
|
||||||
|
String uri = qs.getResource("resource").getURI();
|
||||||
|
if(seen.contains(uri)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String label = getFirstNotNull(new Literal[]{qs.getLiteral("en_label"),qs.getLiteral("label")});
|
||||||
|
|
||||||
|
String description = getFirstNotNull(new Literal[]{qs.getLiteral("en_definition"),qs.getLiteral("definition"),
|
||||||
|
qs.getLiteral("en_description"),qs.getLiteral("description")}) ;
|
||||||
|
RDFSProperty prop = new RDFSProperty(uri, label, description,prefix,namespace);
|
||||||
|
vocab.addProperty(prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
return vocab;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFirstNotNull(Literal[] literals){
|
||||||
|
String s = null;
|
||||||
|
for(int i=0;i<literals.length;i++){
|
||||||
|
s = getString(literals[i]);
|
||||||
|
if(s!=null){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getString(Literal l){
|
||||||
|
if(l!=null){
|
||||||
|
return l.getString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,242 @@
|
|||||||
|
package com.metaweb.gridworks.rdf.vocab;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||||
|
import org.apache.lucene.document.Document;
|
||||||
|
import org.apache.lucene.document.Field;
|
||||||
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
|
import org.apache.lucene.index.IndexWriter;
|
||||||
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queryParser.ParseException;
|
||||||
|
import org.apache.lucene.queryParser.QueryParser;
|
||||||
|
import org.apache.lucene.search.IndexSearcher;
|
||||||
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.apache.lucene.search.TermQuery;
|
||||||
|
import org.apache.lucene.search.TopDocs;
|
||||||
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.store.SimpleFSDirectory;
|
||||||
|
import org.apache.lucene.util.Version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fadmaa
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class VocabularyManager {
|
||||||
|
|
||||||
|
private static final String INDEX_PATH = "luceneIndex";
|
||||||
|
private static final String CLASS_TYPE = "class";
|
||||||
|
private static final String PROPERTY_TYPE = "property";
|
||||||
|
private static final String VOCABULARY_TYPE = "vocabulary";
|
||||||
|
|
||||||
|
private IndexWriter writer;
|
||||||
|
private IndexSearcher searcher;
|
||||||
|
|
||||||
|
private Directory _directory;
|
||||||
|
|
||||||
|
public static VocabularyManager singleton;
|
||||||
|
|
||||||
|
private List<Vocabulary> vocabularies = new ArrayList<Vocabulary>();
|
||||||
|
|
||||||
|
static{
|
||||||
|
singleton = new VocabularyManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
private VocabularyManager(){
|
||||||
|
try{
|
||||||
|
synchronized (this) {
|
||||||
|
_directory = new SimpleFSDirectory(new File(INDEX_PATH));
|
||||||
|
writer = new IndexWriter(_directory, new StandardAnalyzer(Version.LUCENE_30), true, IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
searcher = new IndexSearcher(_directory);
|
||||||
|
updateVocabulariesList();
|
||||||
|
}
|
||||||
|
} catch (CorruptIndexException e) {
|
||||||
|
throw new RuntimeException("Failed initialize vocabulary search",e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed initialize vocabulary search",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param url where to get the vocabulary description from
|
||||||
|
* @param prefix preferred prefix for vocabulary e.g. foaf, dc, skos, dcat
|
||||||
|
* @param namespace the base URI of the vocabulary. usually but not alway the same as url
|
||||||
|
* @param format the format of the RDF description of the vocabulary at the end of url (default to RDF/XML)
|
||||||
|
* @throws IOException
|
||||||
|
* @throws CorruptIndexException
|
||||||
|
* @throws VocabularyExistException
|
||||||
|
*/
|
||||||
|
public void addVocabulary(String url, String prefix, String namespace, String format) throws CorruptIndexException, IOException, VocabularyExistException{
|
||||||
|
if (defined(namespace)){
|
||||||
|
throw new VocabularyExistException(namespace + " already exists!");
|
||||||
|
}
|
||||||
|
VocabularyImporter importer = new VocabularyImporter();
|
||||||
|
Vocabulary vocabulary = importer.getVocabulary(url,prefix,namespace,format);
|
||||||
|
indexVocabulary(vocabulary);
|
||||||
|
updateSearcher();
|
||||||
|
// updateVocabulariesList();
|
||||||
|
this.vocabularies.add(vocabulary);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVocabulary(String url, String prefix, String namespace) throws CorruptIndexException, IOException, VocabularyExistException{
|
||||||
|
addVocabulary(url, prefix, namespace,"RDF/XML");
|
||||||
|
}
|
||||||
|
private void indexVocabulary(Vocabulary v) throws CorruptIndexException, IOException{
|
||||||
|
Document doc = new Document();
|
||||||
|
doc.add(new Field("type",VOCABULARY_TYPE,Field.Store.YES,Field.Index.NOT_ANALYZED));
|
||||||
|
doc.add(new Field("name",v.getName(),Field.Store.YES,Field.Index.NO));
|
||||||
|
doc.add(new Field("uri",v.getUri(),Field.Store.YES,Field.Index.NOT_ANALYZED));
|
||||||
|
writer.addDocument(doc);
|
||||||
|
|
||||||
|
for(RDFSClass c:v.getClasses()){
|
||||||
|
indexRdfNode(c, CLASS_TYPE);
|
||||||
|
}
|
||||||
|
for(RDFSProperty p:v.getProperties()){
|
||||||
|
indexRdfNode(p, PROPERTY_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RDFNode> searchClasses(String str)throws ParseException, IOException{
|
||||||
|
List<RDFNode> res = new ArrayList<RDFNode>();
|
||||||
|
org.apache.lucene.search.Query query = prepareQuery(str, "class");
|
||||||
|
TopDocs docs = searcher.search(query, 1000);
|
||||||
|
for(int i=0;i<docs.totalHits;i++){
|
||||||
|
Document doc= searcher.doc(docs.scoreDocs[i].doc);
|
||||||
|
String uri = doc.get("uri");
|
||||||
|
String label = doc.get("label");
|
||||||
|
String description = doc.get("description");
|
||||||
|
String namespace = doc.get("namespace");
|
||||||
|
String prefix = doc.get("prefix");
|
||||||
|
RDFSClass node = new RDFSClass(uri,label,description,prefix,namespace);
|
||||||
|
res.add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RDFNode> searchProperties(String str)throws ParseException, IOException{
|
||||||
|
List<RDFNode> res = new ArrayList<RDFNode>();
|
||||||
|
org.apache.lucene.search.Query query = prepareQuery(str, "property");
|
||||||
|
TopDocs docs = searcher.search(query, 1000);
|
||||||
|
for(int i=0;i<docs.totalHits;i++){
|
||||||
|
Document doc= searcher.doc(docs.scoreDocs[i].doc);
|
||||||
|
String uri = doc.get("uri");
|
||||||
|
String label = doc.get("label");
|
||||||
|
String description = doc.get("description");
|
||||||
|
String namespace = doc.get("namespace");
|
||||||
|
String prefix = doc.get("prefix");
|
||||||
|
RDFNode node = new RDFSProperty(uri,label,description,prefix,namespace);
|
||||||
|
res.add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Vocabulary> getVocabularies(){
|
||||||
|
return vocabularies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteVocabulary(String uri) throws IOException{
|
||||||
|
Vocabulary vocab = null;
|
||||||
|
for(Vocabulary v:vocabularies){
|
||||||
|
if(v.getUri().equals(uri)){
|
||||||
|
vocab = v;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(vocab==null){
|
||||||
|
throw new RuntimeException("Vocabulary " + uri + " not found");
|
||||||
|
}
|
||||||
|
vocabularies.remove(vocab);
|
||||||
|
Term t = new Term("uri",uri);
|
||||||
|
writer.deleteDocuments(t);
|
||||||
|
t = new Term("namespace",uri);
|
||||||
|
writer.deleteDocuments(t);
|
||||||
|
|
||||||
|
writer.commit();
|
||||||
|
updateSearcher();
|
||||||
|
}
|
||||||
|
|
||||||
|
private org.apache.lucene.search.Query prepareQuery(String s,String type)throws ParseException{
|
||||||
|
QueryParser parser = new QueryParser(Version.LUCENE_30,"description",new StandardAnalyzer(Version.LUCENE_30));
|
||||||
|
String queryStr = "type:" + type ;
|
||||||
|
if(s!=null && s.trim().length()>0){
|
||||||
|
s =s.trim();
|
||||||
|
if(s.indexOf("*")==-1){
|
||||||
|
s += "*";
|
||||||
|
}
|
||||||
|
if(s.indexOf(":")==-1){
|
||||||
|
queryStr += " AND (curie:" + s ;
|
||||||
|
queryStr += " OR description:" + s ;
|
||||||
|
queryStr += " OR label:" + s + ")";
|
||||||
|
}else{
|
||||||
|
String p1 = s.substring(0,s.indexOf(":"));
|
||||||
|
String p2 = s.substring(s.lastIndexOf(":")+1);
|
||||||
|
queryStr += " AND prefix:" + p1;
|
||||||
|
if(p2.length()>1){
|
||||||
|
//queryStr += " AND (description:" + p2;
|
||||||
|
queryStr += " AND label:" + p2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return parser.parse(queryStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void indexRdfNode(RDFNode node, String type) throws CorruptIndexException, IOException{
|
||||||
|
//TODO weight fields... setBoost
|
||||||
|
Document doc = new Document();
|
||||||
|
doc.add(new Field("type",type,Field.Store.YES,Field.Index.NOT_ANALYZED));
|
||||||
|
doc.add(new Field("prefix",node.getVocabularyPrefix(),Field.Store.YES,Field.Index.NOT_ANALYZED));
|
||||||
|
String l = node.getLabel()==null?"":node.getLabel();
|
||||||
|
Field labelField = new Field("label",l,Field.Store.NO,Field.Index.ANALYZED);
|
||||||
|
doc.add(labelField);
|
||||||
|
String d = node.getDescription()==null?"":node.getDescription();
|
||||||
|
Field descriptionField = new Field("description",d,Field.Store.YES,Field.Index.ANALYZED);
|
||||||
|
doc.add(descriptionField);
|
||||||
|
doc.add(new Field("uri", node.getURI(),Field.Store.YES,Field.Index.NO));
|
||||||
|
Field curieField = new Field("curie", node.getPreferredCURIE(),Field.Store.YES,Field.Index.ANALYZED);
|
||||||
|
doc.add(curieField);
|
||||||
|
Field namespaceField = new Field("namespace", node.getVocabularyUri(),Field.Store.YES,Field.Index.NOT_ANALYZED);
|
||||||
|
doc.add(namespaceField);
|
||||||
|
writer.addDocument(doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateVocabulariesList() throws IOException{
|
||||||
|
Term typeTerm = new Term("type", VOCABULARY_TYPE);
|
||||||
|
Query query = new TermQuery(typeTerm);
|
||||||
|
//TODO 1000 :O
|
||||||
|
TopDocs vocabDocs = searcher.search(query, 1000);
|
||||||
|
for(int i=0;i<vocabDocs.totalHits;i++){
|
||||||
|
Document doc = searcher.doc(vocabDocs.scoreDocs[i].doc);
|
||||||
|
String name = doc.get("name");
|
||||||
|
String uri = doc.get("uri");
|
||||||
|
Vocabulary vocab = new Vocabulary(name, uri);
|
||||||
|
this.vocabularies.add(vocab);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSearcher() throws IOException{
|
||||||
|
this.searcher = new IndexSearcher(_directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean defined(String namespace){
|
||||||
|
if(namespace==null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
namespace = namespace.trim();
|
||||||
|
for(Vocabulary v:vocabularies){
|
||||||
|
if(v.getUri().equals(namespace)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user