Permalink
Browse files

finalized chaining

  • Loading branch information...
1 parent a6db980 commit 0de4e40221ded3022442a81f6d8a586a90e42b59 Sebastian Germesin committed Feb 25, 2011
Showing with 161 additions and 103 deletions.
  1. +11 −1 README.txt
  2. +11 −12 demos/smartlist/css/demo.css
  3. +13 −11 demos/smartlist/index.html
  4. +18 −20 demos/smartlist/js/demo.js
  5. +2 −8 src/core/context.js
  6. +4 −5 src/core/smartobject.js
  7. +22 −9 src/dsf/companies.js
  8. +36 −15 src/dsf/employees.js
  9. +44 −22 src/dsf/persons.js
View
@@ -1,3 +1,13 @@
== Semantic Interaction Framework ==
-Initial commit.
+=== Vision ===
+
+fill:
+$('#summary').sif('analyze');
+filter:
+$('#summary').sif('companies').sif('persons');
+###############################
+write:
+$('#summary ul li').sif('serialize', ???);
+store:
+$('#summary ul li').sif('store', 'stanbol', ???);
@@ -1,4 +1,5 @@
body {
+ overflow: scroll;
margin:0;
font-family: Trebuchet, Verdana, sans-serif;
font-size:90%;
@@ -16,19 +17,17 @@ body {
color:#9E9E9E;
}
-/*
-a {
- color: #8B0000;
- border-bottom: 1px dashed #8B0000;
- text-decoration:none;
- cursor:pointer;
-}*/
-
-#editable {
- padding:5px;
- margin-top:10px;
+pre {
+ border: 1px solid #E2E1D5;
+ background-color: #FBF9EA;
+ font-size:80%;
+ font-family: monaco, monospaced;
+ color: #444444;
}
*[smart="true"] {
- background-color:#90EE90;
+ margin-top:10px;
+ margin-bottom:10px;
+ padding: 1px 5px 1px 10px;
+ background-color:#d0f9ce;
}
View
@@ -52,7 +52,9 @@
<script type="text/javascript" src="../../src/core/connectormanager.js"></script>
<script type="text/javascript" src="../../src/core/context.js"></script>
<script type="text/javascript" src="../../src/core/contextmanager.js"></script>
- <!--<script type="text/javascript" src="../../dist/min/jquery.sif-0.1.min.js"></script>-->
+ <script type="text/javascript" src="../../src/core/dsf.js"></script>
+ <script type="text/javascript" src="../../src/core/dsfmanager.js"></script>
+ <!--<script type="text/javascript" src="../../dist/min/jquery.sif-0.1.min.js"></script>-->
<!-- SIF - connectors -->
<script type="text/javascript" src="../../src/connectors/stanbol.js"></script>
@@ -63,6 +65,7 @@
<script type="text/javascript" src="../../src/dsf/analyze.js"></script>
<script type="text/javascript" src="../../src/dsf/companies.js"></script>
<script type="text/javascript" src="../../src/dsf/persons.js"></script>
+ <script type="text/javascript" src="../../src/dsf/employees.js"></script>
<!-- SIF - Configurations -->
<script type="text/javascript">
@@ -91,10 +94,10 @@
$('#summary').aloha();
$('#summary').find('li').autocomplete({
source: function(request, response) {
- var persons = $('[smart="true"]').sif().persons(),
+ var persons = $('#summary').sif('companies').sif('employees'),
names = [];
// loop through connectors
- $.each( persons, function() {
+ $.each( persons.matches, function() {
// loop through people
$.each( this, function() {
names.push( this.name.toString().replace( /^"([^"]+)".+/, "$1" ) );
@@ -104,7 +107,7 @@
}
});
//semantify the abstract object
- $('[smart="true"]').sif().analyze(); //triggers abs.'contextChanged'
+ $('#summary').sif('analyze'); //triggers abs.'contextChanged'
});
</script>
@@ -176,7 +179,7 @@
<span property="v:lastname">Becker</span>
<span property="v:mbox">becker@dfki.de</span>
<span rel="v:affiliation">
- <span typeof="v:Organization" about="#gentics"></span>
+ <span typeof="v:Organization" about="#dfki"></span>
</span>
<span property="v:role" content="Senior Researcher"></span>
</span>
@@ -204,16 +207,15 @@
</div>
<hr/>
<hr/>
- <button onclick="var x = $('[smart]').sif('companies');debugger;var y = x.sif('persons');debugger;">test</button>
<table>
<tr>
<td style="width:300px;vertical-align:top;"><div id="companies">
<h3>Tags - Companies</h3>
- <button onclick="presentEntitiesAsTags($('[smart]').sif('companies'), $('#companies'));$(this).attr('disabled', 'disabled');">Retrieve all companies</button>
+ <button onclick="presentEntitiesAsTags($('#summary').sif('companies'), $('#companies'));$(this).attr('disabled', 'disabled');">Retrieve all companies</button>
</div></td>
<td style="width:300px;vertical-align:top;"><div id="persons">
<h3>Tags - Persons</h3>
- <button onclick="presentEntitiesAsTags($('[smart]').sif('persons'), $('#persons'));$(this).attr('disabled', 'disabled');">Retrieve all persons</button>
+ <button onclick="presentEntitiesAsTags($('#summary').sif('persons'), $('#persons'));$(this).attr('disabled', 'disabled');">Retrieve all persons</button>
<div class="info"></div>
</div></td>
</tr>
@@ -248,14 +250,14 @@ <h4 style="display:inline">Code explanation:</h4><input onclick="$(this).attr('c
<pre>
$(function() {
//semantify the abstract object
- $('#summary').sif().analyze(); //triggers 'contextChanged' on $('#summary')
+ $('#summary').sif('analyze'); //triggers 'contextChanged' on $('#summary')
});</pre>
</p>
<p>Query for found persons:
- <pre>$('#summary').sif().persons();</pre>
+ <pre>$('#summary').sif('persons');</pre>
</p>
<p>Query for found places:
- <pre>$('#summary').sif().places();</pre>
+ <pre>$('#summary').sif('places');</pre>
</p>
</span>
</div>
View
@@ -2,23 +2,21 @@
* Demo-specific methods.
*/
-function presentEntitiesAsTags (rdfs, field) {
- var foundEntities = [];
- for (var i in rdfs.matches) {
- var rdf = rdfs.matches[i];
- for (var e = 0; e < rdf.matches.length; e++) {
- var entity = rdf[e];
- var name = entity.name;
- var confidence = (entity.confidence) ? parseFloat((entity.confidence.toString()).replace(/"/g, "")) : 100.0;
- foundEntities.push({
- value: e,
- name: name.toString().replace(/"/g, ""),
- confidence: confidence
- });
- }
- }
- for (var x = 0; x < foundEntities.length; x++) {
- var name = foundEntities[x].name;
- field.append($("<div>").text(name.replace(/@en/, "")));
- }
- }
+function presentEntitiesAsTags (companies, field) {
+ var foundEntities = [];
+ $.each (companies.matches, function () {
+ var entity = this;
+ var name = entity.name;
+ var confidence = (entity.confidence) ? parseFloat((entity.confidence.toString()).replace(/"/g, "")) : 100.0;
+ foundEntities.push({
+ value: entity,
+ name: name.toString().replace(/"/g, ""),
+ confidence: confidence
+ });
+ });
+ for (var x = 0; x < foundEntities.length; x++) {
+ var name = foundEntities[x].name;
+ console.info(name);
+ field.append($("<div>").text(name.replace(/@en/, "")));
+ }
+}
View
@@ -48,17 +48,13 @@ SIF.Context.prototype.init = function() {
/**
* Add all triples in the {jQuery.rdf} object to the current context.
- * @param {SIF.Connector} connector The connector that was used to retrieve the data.
- * If it is 'undefined', the triples go to {this.rdf.noconnector}.
+ * @param {SIF.Connector} connector The connector that was used to retrieve the data.
* @trigger Triggers the 'contextChanged' event on the parentObject.
*/
SIF.Context.prototype.update = function (rdf, connector) {
if (connector === undefined) {
- var triples = rdf.databank.triples();
- triples.each(function (i, e) {
- that.rdf.noconnector.add(e);
- });
+ SIF.log("error", "SIF.Context.update(rdf, undefined)", "TO BE IMPLEMENTED");
}
else if (!this.rdf[connector.id]) {
this.rdf[connector.id] = jQuery.rdf();
@@ -69,8 +65,6 @@ SIF.Context.prototype.update = function (rdf, connector) {
});
}
-
-
SIF.EventRegistry.trigger(new SIF.Event("contextChanged", this.parentObject, null));
}
View
@@ -40,22 +40,21 @@ SIF.Smartobject = function (obj) {
* Needed for chaining.
*/
SIF.Smartobject.prototype.sif = function(method) {
- var args = Array.prototype.slice.call(arguments, 1),
- smartObject = SIF.getSmartObject(jQuery(this));
+ var args = Array.prototype.slice.call(arguments, 1);
if ( arguments.length ) {
- return smartObject[method].apply(smartObject, args);
+ return this[method].apply(this, args);
}
return smartObject;
};
-SIF.Smartobject.prototype.matches = {};
+SIF.Smartobject.prototype.matches = undefined;
SIF.Smartobject.prototype.copy = function () {
var copy = new SIF.Smartobject();
copy.id = this.id;
copy.object = this.object;
copy.context = this.context;
- copy.matches = this.matches;
+ copy.matches = {};
return copy;
}
View
@@ -46,6 +46,7 @@ SIF.Dsfs.companies.init = function () {
* @example
* var company =
* {
+ * uri : jQuery.uri("..."),
* name : "DFKI GmbH",
* latitude : "49.23485",
* longitude : "6.994402",
@@ -55,30 +56,42 @@ SIF.Dsfs.companies.init = function () {
*/
SIF.Smartobject.prototype.companies = function () {
var copy = this.copy();
+ copy.matches = [];
for (var connectorId in SIF.ConnectorManager.connectors) {
var mapper = SIF.Dsfs.companies.connectorMappers[connectorId];
if (mapper) {
var rdf = copy.getContext().rdf[connectorId];
if (rdf) {
- copy.matches[connectorId] = mapper(rdf);
- } else {
- copy.matches[connectorId] = jQuery.rdf();
+ copy.matches = copy.matches.concat(mapper(rdf, this.matches));
}
}
}
return copy;
}
-SIF.Dsfs.companies.connectorMappers['sif.connector.Rdfa'] = function (rdf) {
+/**
+ * Returns an array of companies.
+ */
+SIF.Dsfs.companies.connectorMappers['sif.connector.Rdfa'] = function (rdf, matches) {
+ var ret = [];
- var ret = rdf
+ rdf
.where('?subject <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdf.data-vocabulary.org/#Organization>')
.where('?subject <http://rdf.data-vocabulary.org/#name> ?name')
.optional('?subject <http://rdf.data-vocabulary.org/#url> ?url')
.optional('?subject <http://rdf.data-vocabulary.org/#latitude> ?latitude')
- .optional('?subject <http://rdf.data-vocabulary.org/#longitude> ?longitude');
-
- return ret;
-
+ .optional('?subject <http://rdf.data-vocabulary.org/#longitude> ?longitude')
+ .each (function () {
+ var company = {
+ uri : this.subject,
+ name : this.name.toString(),
+ url : (this.url)? this.url.toString() : undefined,
+ latitude : (this.latitude)? this.latitude.toString() : undefined,
+ longitude : (this.longitude)? this.longitude.toString() : undefined
+ };
+ ret.push(company);
+ });
+
+ return ret;
}
View
@@ -55,33 +55,54 @@ SIF.Dsfs.employees.init = function () {
*/
SIF.Smartobject.prototype.employees = function () {
var copy = this.copy();
+ copy.matches = {};
for (var connectorId in SIF.ConnectorManager.connectors) {
var mapper = SIF.Dsfs.employees.connectorMappers[connectorId];
if (mapper) {
var rdf = copy.getContext().rdf[connectorId];
if (rdf) {
- copy.matches[connectorId] = mapper(rdf);
+ copy.matches[connectorId] = mapper(rdf, this.matches);
} else {
- copy.matches[connectorId] = jQuery.rdf();
+ copy.matches[connectorId] = [];
}
}
}
return copy;
}
-SIF.Dsfs.employees.connectorMappers['sif.connector.Rdfa'] = function (rdf) {
- //TODO: only work on the matches!
- var ret = rdf
- .where('?p <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdf.data-vocabulary.org/#Person>')
- .where('?a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdf.data-vocabulary.org/#Organization>')
- .where('?a <http://rdf.data-vocabulary.org/#name> ?aname')
- .filter("aname", "GENTICS")
- .where('?p <http://rdf.data-vocabulary.org/#affiliation> ?a')
- .where('?p <http://rdf.data-vocabulary.org/#firstname> ?name')
- .where('?p <http://rdf.data-vocabulary.org/#lastname> ?lastname')
- .where('?p <http://rdf.data-vocabulary.org/#mbox> ?email');
-
+/**
+ * Returns an array of {@link jQuery.uri}s.
+ */
+SIF.Dsfs.employees.connectorMappers['sif.connector.Rdfa'] = function (rdf, matches) {
+ var ret = [];
+ rdf
+ .where('?subject <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdf.data-vocabulary.org/#Person>')
+ .where('?subject <http://rdf.data-vocabulary.org/#affiliation> ?affiliation')
+ .where('?subject <http://rdf.data-vocabulary.org/#firstname> ?name')
+ .where('?subject <http://rdf.data-vocabulary.org/#lastname> ?lastname')
+ .where('?subject <http://rdf.data-vocabulary.org/#mbox> ?email')
+ .filter(function () {
+ var affiliation = this.affiliation;
+ var contains = false;
+ $.each (matches, function () {
+ if (this.uri.toString() === affiliation.toString()) {
+ contains = true;
+ return;
+ }
+ });
+ return contains;
+ })
+ .each (function () {
+ var employee = {
+ uri : this.subject,
+ affiliation : this.affiliation,
+ name : this.name.toString(),
+ lastname : this.lastname.toString(),
+ email: this.email.toString()
+ };
+ ret.push(employee);
+ });
+
return ret;
-
}
Oops, something went wrong.

0 comments on commit 0de4e40

Please sign in to comment.