diff --git a/extensions/rdf-exporter/.classpath b/extensions/rdf-exporter/.classpath new file mode 100644 index 000000000..fe978b453 --- /dev/null +++ b/extensions/rdf-exporter/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/extensions/rdf-exporter/.project b/extensions/rdf-exporter/.project new file mode 100644 index 000000000..99d97a560 --- /dev/null +++ b/extensions/rdf-exporter/.project @@ -0,0 +1,17 @@ + + + rdf-exporter + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/extensions/rdf-exporter/LICENSE.txt b/extensions/rdf-exporter/LICENSE.txt new file mode 100644 index 000000000..26f1bc56d --- /dev/null +++ b/extensions/rdf-exporter/LICENSE.txt @@ -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 diff --git a/extensions/rdf-exporter/build.xml b/extensions/rdf-exporter/build.xml new file mode 100644 index 000000000..c4aef7da2 --- /dev/null +++ b/extensions/rdf-exporter/build.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/rdf-exporter/licenses/arq.LICENSE.txt b/extensions/rdf-exporter/licenses/arq.LICENSE.txt new file mode 100644 index 000000000..85a3c7cce --- /dev/null +++ b/extensions/rdf-exporter/licenses/arq.LICENSE.txt @@ -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. \ No newline at end of file diff --git a/extensions/rdf-exporter/licenses/iri.LICENSE.txt b/extensions/rdf-exporter/licenses/iri.LICENSE.txt new file mode 100644 index 000000000..93b2900d7 --- /dev/null +++ b/extensions/rdf-exporter/licenses/iri.LICENSE.txt @@ -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. + diff --git a/extensions/rdf-exporter/licenses/jena.LICENSE.txt b/extensions/rdf-exporter/licenses/jena.LICENSE.txt new file mode 100644 index 000000000..07cca6a16 --- /dev/null +++ b/extensions/rdf-exporter/licenses/jena.LICENSE.txt @@ -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. \ No newline at end of file diff --git a/extensions/rdf-exporter/module/MOD-INF/controller.js b/extensions/rdf-exporter/module/MOD-INF/controller.js new file mode 100755 index 000000000..c2450f251 --- /dev/null +++ b/extensions/rdf-exporter/module/MOD-INF/controller.js @@ -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", + ] + ); +} diff --git a/extensions/rdf-exporter/module/MOD-INF/lib/arq-2.7.0.jar b/extensions/rdf-exporter/module/MOD-INF/lib/arq-2.7.0.jar new file mode 100755 index 000000000..90c458c4b Binary files /dev/null and b/extensions/rdf-exporter/module/MOD-INF/lib/arq-2.7.0.jar differ diff --git a/extensions/rdf-exporter/module/MOD-INF/lib/arq-extra-2.7.0.jar b/extensions/rdf-exporter/module/MOD-INF/lib/arq-extra-2.7.0.jar new file mode 100755 index 000000000..72cb9c7d6 Binary files /dev/null and b/extensions/rdf-exporter/module/MOD-INF/lib/arq-extra-2.7.0.jar differ diff --git a/extensions/rdf-exporter/module/MOD-INF/lib/iri-0.6.jar b/extensions/rdf-exporter/module/MOD-INF/lib/iri-0.6.jar new file mode 100755 index 000000000..b2026e455 Binary files /dev/null and b/extensions/rdf-exporter/module/MOD-INF/lib/iri-0.6.jar differ diff --git a/extensions/rdf-exporter/module/MOD-INF/lib/jena-2.6.0.jar b/extensions/rdf-exporter/module/MOD-INF/lib/jena-2.6.0.jar new file mode 100755 index 000000000..6a532bd43 Binary files /dev/null and b/extensions/rdf-exporter/module/MOD-INF/lib/jena-2.6.0.jar differ diff --git a/extensions/rdf-exporter/module/MOD-INF/lib/lucene-core-3.0.1.jar b/extensions/rdf-exporter/module/MOD-INF/lib/lucene-core-3.0.1.jar new file mode 100755 index 000000000..411524695 Binary files /dev/null and b/extensions/rdf-exporter/module/MOD-INF/lib/lucene-core-3.0.1.jar differ diff --git a/extensions/rdf-exporter/module/MOD-INF/lib/xercesImpl-2.7.1.jar b/extensions/rdf-exporter/module/MOD-INF/lib/xercesImpl-2.7.1.jar new file mode 100755 index 000000000..eac75ae8e Binary files /dev/null and b/extensions/rdf-exporter/module/MOD-INF/lib/xercesImpl-2.7.1.jar differ diff --git a/extensions/rdf-exporter/module/MOD-INF/module.properties b/extensions/rdf-exporter/module/MOD-INF/module.properties new file mode 100755 index 000000000..8a8308772 --- /dev/null +++ b/extensions/rdf-exporter/module/MOD-INF/module.properties @@ -0,0 +1,4 @@ +name = rdf-exporter +description = Freebase Gridworks RDF export +templating = false +requires = core \ No newline at end of file diff --git a/extensions/rdf-exporter/module/scripts/menu-bar-extensions.js b/extensions/rdf-exporter/module/scripts/menu-bar-extensions.js new file mode 100644 index 000000000..b487965a1 --- /dev/null +++ b/extensions/rdf-exporter/module/scripts/menu-bar-extensions.js @@ -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"); + + $('') + .attr("name", "engine") + .attr("value", JSON.stringify(ui.browsingEngine.getJSON())) + .appendTo(form); + $('') + .attr("name", "project") + .attr("value", theProject.id) + .appendTo(form); + $('') + .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); +}; + diff --git a/extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-link.js b/extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-link.js new file mode 100755 index 000000000..07b902601 --- /dev/null +++ b/extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-link.js @@ -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 = $('
').appendTo(this._tdDetails).addClass("padded").html("..."); + this._expandedDetailDiv = $('
').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(" "); + $('') + .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; + + $('') + .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 = $('') + .addClass("schema-alignment-link-tag") + .html(label) + .appendTo(this._tdMain) + .click(function(evt) { + self._startEditProperty(this); + }); + + $('').attr("src", "images/arrow-start.png").prependTo(a); + $('').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 = $('
').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; +}; \ No newline at end of file diff --git a/extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-node.js b/extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-node.js new file mode 100755 index 000000000..dc3cc7260 --- /dev/null +++ b/extensions/rdf-exporter/module/scripts/rdf-schema-alignment-ui-node.js @@ -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()? '' : '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
 
' + + '
' + + 'add rdf:type' + + '
' + + '
' + + '' + + ''; + var html = $( + '' + + '' + + '' + + '' + + type_html + + '
' + + '
' + ).appendTo(this._tdMain) + ; + + var elmts = DOM.bind(html); + this._tdNodeLabel = elmts.nodeLabel; + if(elmts.addRdfTypeLink){ + var typesTable = $('
')[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').attr("title", "remove type").attr("src", "images/close.png").css("cursor", "pointer").click( + + func(i) + + ); + $(tr).append($('').append(img)); + $(tr).append($('').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 = $('') + .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){ + $('') + .text('Row Number') + .addClass("schema-alignment-node-column") + .prependTo(a); + }else{ + if ("columnName" in this._node) { + a.html(" cell"); + + $('') + .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 = $('').appendTo($(this._tdMain)); + aux_table.append($('').append(td)); + this._typesTd = $('').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 = $('
').appendTo(this._tdDetails).addClass("padded").html("..."); + this._expandedDetailDiv = $('
').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(" "); + $('') + .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 = $('
').attr("width", "250").appendTo($('
').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 = $('
').addClass("padded").appendTo(this._expandedDetailDiv); + + $('') + .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 = $('
').addClass("dialog-header").text("RDF Node").appendTo(frame); + var body = $('
').addClass("dialog-body").appendTo(frame); + var footer = $('
').addClass("dialog-footer").appendTo(frame); + + /*-------------------------------------------------- + * Body + *-------------------------------------------------- + */ + var literalTypeSelectHtml = + '' + + '' + + '' + + //'' + + //'' + + //'' + + ''; + + var html = $( + '' + + '' + + '' + + + + '' + + '' + + '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '
' + + ' Set to Cell in Column' + + '
' + + '
' + + '' + + '' + + '' + + '' + + '' + + '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
The cell\'s content is used ...
as a resource
URI:
preview/edit
as a literal value
Literal type
Language (for text)
as a blank node
* relative URIs will be resolved against base URI
' + + '
' + + '
' + + '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + + '
' + + '
' + + ' Use a constant resource' + + '
' + + '
URI:
' + + '
' + + ' Use a constant literal value' + + '
' + + '
Value
Value type
Language
' + + '
' + + ' Generate a blank node (shared between all rows)' + + '
' + + '
' + + '
' + ).appendTo(body); + + var elmts = DOM.bind(html); + + var tableColumns = $('
') + .attr("cellspacing", "5") + .attr("cellpadding", "0") + .appendTo(elmts.divColumns)[0]; + + var makeColumnChoice = function(column, columnIndex) { + var tr = tableColumns.insertRow(tableColumns.rows.length); + + var radio = $('') + .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'); + } + $('').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; + }; + + $('').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); + + $('').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' + + 'URI: (relative URIs will be resolved against base URI)' + + '
' + + '' + + '' + //'' + ); + 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('