From 3cf954494e1fcd77762e77ffe405d182f41320a1 Mon Sep 17 00:00:00 2001 From: Kirk Hess Date: Thu, 18 Oct 2018 09:43:26 -0400 Subject: [PATCH] v1.0.0 --- .gitignore | 2 +- Gruntfile.js | 2 +- README.md | 4 - docs/bfe-api.md | 192 ++++++++++++++++++++------------------------ docs/bfe-lookups.md | 39 --------- docs/changelog.md | 18 +++++ src/bfe.js | 3 +- src/bfestore.js | 71 +--------------- 8 files changed, 108 insertions(+), 223 deletions(-) mode change 100755 => 100644 docs/bfe-api.md delete mode 100755 docs/bfe-lookups.md diff --git a/.gitignore b/.gitignore index 4362992..884115d 100755 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ tmp examples node_modules builds/* -documentation/* +docs/plato/* *.html static/js/config-*.js diff --git a/Gruntfile.js b/Gruntfile.js index 92d5bf0..03565fa 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -41,7 +41,7 @@ module.exports = function(grunt) { }, tests: { files: { - 'documentation/plato': ['src/**/*.js', 'static/js/config*.js'] + 'docs/plato': ['src/**/*.js', 'static/js/config*.js'] }, }, }, diff --git a/README.md b/README.md index 3174ad7..c1fe90f 100755 --- a/README.md +++ b/README.md @@ -21,7 +21,6 @@ Twitter's [Bootstrap] and a few additional custom CSS declarations. [demo-page]: http://bibframe.org/bibliomata/bfe/index.html [ontology]: http://id.loc.gov/ontologies/bibframe/ [bfi]: http://www.loc.gov/bibframe/ -[profilespec]: http://bibframe.org/documentation/bibframe-profilespec/ Getting Started --------------- @@ -47,10 +46,8 @@ Documentation ------------- * [API] -* [Lookups][lookups-info] [API]: https://github.com/lcnetdev/bfe/blob/master/docs/bfe-api.md -[lookups-info]: https://github.com/lcnetdev/bfe/blob/master/docs/bfe-lookups.md Demo? @@ -187,7 +184,6 @@ Specification][profilespec]. [dryice]: https://github.com/mozilla/dryice [ace]: https://github.com/ajaxorg/ace [Zepheira]: https://zepheira.com/ -[profilespec]: http://bibframe.org/documentation/bibframe-profilespec/ Contributors diff --git a/docs/bfe-api.md b/docs/bfe-api.md old mode 100755 new mode 100644 index 7da624b..53d7e69 --- a/docs/bfe-api.md +++ b/docs/bfe-api.md @@ -9,6 +9,7 @@ Contents * [`bfe`](#bfe) * [Configuring `bfe`](#configuring-bfe) +* [`bfelookup`](#bfelookup) * [`bfestore`](#bfestore) * [`bfelog`](#bfelog) @@ -51,76 +52,17 @@ to load and, if invoking the "full editor," the structure of the left-side menu. Providing a `return` description is generally necessary in order to provide a callback function for when the user hits the `save` button. +#### `config` Properties -#### Example (Kitchen sink) +Required -```javascript -{ - "baseURI": "http://example.org/", - "profiles": [ - "/static/profiles/bibframe/Agents.json", - "/static/profiles/bibframe/Annotations.json", - "/static/profiles/bibframe/Authorities.json", - "/static/profiles/bibframe/Entities.json", - "/static/profiles/bibframe/WIA.json", - ], - "startingPoints": [ - { - "menuGroup": "BIBFRAME Generic", - "menuItems": [ - { - label: "New HeldItem", - useResourceTemplates: [ "profile:bf:HeldItem" ] - }, - { - label: "New Instance", - useResourceTemplates: [ "profile:bf:Instance" ] - }, - { - label: "New Work", - useResourceTemplates: [ "profile:bf:Work" ] - }, - { - label: "New Work, Instance, & HeldItem", - useResourceTemplates: [ "profile:bf:Work", "profile:bf:Instance", "profile:bf:HeldItem" ] - }, - ] - } - ], - "lookups": { - "http://id.loc.gov/authorities/names": { - "name": "LCNAF", - "load": "src/lookups/lcnames" - }, - "http://id.loc.gov/authorities/subjects": { - "name": "LCSH", - "load": "src/lookups/lcsubjects" - } - }, - "load": [ - { - "templateID": "profile:bf:Work", - "defaulturi": "http://id.loc.gov/resources/bibs/5226", - "source": { - "location": "http://id.loc.gov/resources/bibs/5226.bibframe_raw.jsonp", - "requestType": "jsonp" - } - }, - { - "templateID": "profile:bf:Instance", - "defaulturi": "_:b105resourcesbibs5226" - } - ], - "return": { - "format": "jsonld-expanded", - "callback": myCB - } -} -``` +* `url`: (String) the url for the server, which in the example config is set to + rectoBase, which by default is `http://localhost:3000`, or the value of RECTOBASE + which is set in env.js by env.sh. -#### `config` Properties +* `baseURI`: (String) the base URI to use when minting new identifiers. Defaults + to `http://example.org/`. -Required * `profiles`: (Array) locations (URLs) of Profiles to be loaded. Profiles should be in the form of a JSON array with one or more objects that contain a "name" and a "json" property with the @@ -150,46 +92,75 @@ Required `useResourceTemplates` expects the identifier value of a resource template (not the identifer for a Profile). If more than one resource template identifier is listed, then the multiple resource templates are combine into one form for - editing. For more about the distinction see the [BIBFRAME Profile Specification][profilespec]. - + editing. +```json +"startingPoints": [ + {"menuGroup": "Monograph", + "menuItems": [ + { + label: "Instance", + type: ["http://id.loc.gov/ontologies/bibframe/Instance"], + useResourceTemplates: [ "profile:bf2:Monograph:Instance" ] + }, + { + label: "Work", + type: ["http://id.loc.gov/ontologies/bibframe/Work"], + useResourceTemplates: [ "profile:bf2:Monograph:Work" ] + } + + ]} + ] +``` Optional -* `baseURI`: (String) the base URI to use when minting new identifiers. Defaults - to `http://example.org/`. -* `load`: (Array) Instructs which resource templates to automatically load into - the editor. This is essential when using the "form only" editor. Each member - of the `load` object contains minimally one property, `templateID`. - `templateID` is the resource template identifier of the resource template to - be loaded. Each resource template - each object - represents a resource. - If multiple objects are specified, the resource templates will be - combined and displayed as one large form, similar to identifing multiple resource - template identifiers of the `useResourceTemplates` property of a menu item (see - `startingPoints` above). Each object may also specify a `defaultURI` to use - for the resource being loaded/edited. In order to "edit" existing data, the - `source` property should be used. `source` is an object that indicates the - `location` of the data to be loaded for editing and the `requestType`. `location` - should be a full URL (content-negotation is not supported). `requestType` may - be either 'jsonp' or 'json'. 'json' should only be used when not attempting a - cross-domain request. +* `basedbURI`: URI for posting triples for publication in a triplestore +* `resourceURI`: Base URI for resources in the triplestore. * `logging`: (Object) with two properties. `level` indicates the level of logging desired. INFO and DEBUG are the two options. DEBUG is verbose. Default is INFO. `toConsole` is a boolean value. "True" will write the output to the - Javascript console during runtime. Default is "True". -* `lookups`: (Object) an object of objects. The object's key is a scheme identifier - used or expected to be used with the `useValuesFrom` property constraint from - a property in a property template which is part of a profile's resource template. - For more about the `useValuesFrom` property, see the [Profile Specification][profilespec]. - Each object consists of two properties. `name` is a label/identifier for the lookup. - It is used by the typeahead library. `load` is the location of the Javascript - file the contains the functions required to populate the typeahead drop down - selection list and then to process the selected item. You can read more about [lookups - here][lookups-info]. - + Javascript console during runtime. Default is "True". +* lookups: (Object) an object of objects. The object's key is a scheme identifier used or + expected to be used with the useValuesFrom property constraint from a property in a + property template which is part of a profile's resource template. Each object consists of + two properties. name is a label/identifier for the lookup. It is used by the typeahead library. + load is the location of the Javascript file the contains the functions required to populate + the typeahead drop down selection list and then to process the selected item. +---------------- -[profilespec]: http://bibframe.org/documentation/bibframe-profilespec/ -[lookups-info]: https://github.com/lcnetdev/bfe/blob/master/docs/bfe-lookups.md +### `bfelookup` + +`bfe` Lookups +---------------- + +A `bfe` lookup is a Javascript function that contains logic to fetch typeahead suggestions, +format those suggestions for display, and, after a suggestion is selected, a +lookup performs post-selection processing and returns the data to the editor. + +Each lookup must contain three exported objects: + +* `scheme` - (String) representing the scheme identifier. This is used to match + the lookup with the appropriate declaration in the `useValuesFrom` declaration + in the profile. +* `source` - (Function) expects two parameters - `query, process` - and + ultimately returns a list of objects each with a `uri` property and `value` + property, the latter containing the humand readable text to display. +* `getResource` - (Function) expects four parameters: `subjecturi, propertyuri, + selected, process`. `subjecturi` is the URI for the resource being described. + `propertyuri` is the property uri of the property that invoked the lookup. + `selected` is the selected item, it has two properties `uri` and `value`, about + which see `source` above. Finally, `process` is the callback. At the end, `process` is called with + one parameter, which is an array of triples formatted according to the [`bfestore`](#bfestore). + It is not necessary to include the `guid` property for each triple; that is added + after the data is returned to the editor. + +Lookups can be created and dynamically loaded at run time. See [configuring +`bfe`](#configuring-bfe). If a 'key' of a dynamically loaded lookup is the same +as a pre-existing/pre-loaded lookup, the pre-loaded one is overwritten and not +used. + + ---------------- @@ -224,21 +195,27 @@ Is the store itself. The store is an array of triples of the following form. } ] ``` +#### bfe.bfestore.jsonld2store +Expects expanded jsonld, and converts the jsonld to an array of triples. + +#### bfe.bfestore.rdfxml2store +Using ajax uses `http://rdf-translator.appstpot.com` to convert rdfxml to jsonld, which used the helper function `jsonldcompascted2store` to expand the jsonld and normalize blanknodes and identifiers. Used with Load Marc in editor. -#### bfe.bfestore.storeDedup() +#### bfe.bfestore.store2rdfxml -Returns the store after deduping. Nominally clears the store of duplicate triples. -It is usually not necessary to call this; the store is deduped before calling the -below methods. +Using jsonld, converts the jsonld to nquads, which is converted to turtle by N3.js. The prefixes are set and the turtle +is sent to rapper using a rest api on recto. Used in the preview pane. -#### bfe.bfestore.store2text() +#### bfe.bfestore.n32store -Returns the store formatted as text. This is a throw away function designed to -provide quick and dirty human-readable access to the data in the store. +Using N3.js, convert n3/turtle to quads, which is passed to jsonld, expanded and pushed into the bfestore. -#### bfe.bfestore.store2jsonldExpanded() +#### bfe.bfestore.store2turtle() -Returns the store as JSON object formatted according to jsonld expanded syntax. +Returns the store formatted as turtle, for use in the preview pane. + +#### bfe.bfestore.store2jsonldcompacted +Returns the store formatted as compacted jsonld, for use in the preview pane. ---------------- @@ -286,3 +263,4 @@ Returns the log as a JSON object. Sample: ``` + diff --git a/docs/bfe-lookups.md b/docs/bfe-lookups.md deleted file mode 100755 index 8c4fc53..0000000 --- a/docs/bfe-lookups.md +++ /dev/null @@ -1,39 +0,0 @@ -`bfe` Lookups ----------------- - -A `bfe` lookup is a Javascript file that contains logic to fetch typeahead suggestions, -format those suggestions for display, and, after a suggestion is selected, a -lookup performs post-selection processing and returns the data to the editor. - -The best thing to do is look at an example: - -https://github.com/lcnetdev/bfe/blob/master/src/lookups/rdacarriers.js - -**Note**: The above file calls a helper file, in which some of the magic happens. - -Each lookup must contain three exported objects: - -* `scheme` - (String) representing the scheme identifier. This is used to match - the lookup with the appropriate declaration in the `useValuesFrom` declaration - in the profile. -* `source` - (Function) expects two parameters - `query, process` - and - ultimately returns a list of objects each with a `uri` property and `value` - property, the latter containing the humand readable text to display. -* `getResource` - (Function) expects four parameters: `subjecturi, propertyuri, - selected, process`. `subjecturi` is the URI for the resource being described. - `propertyuri` is the property uri of the property that invoked the lookup. - `selected` is the selected item, it has two properties `uri` and `value`, about - which see `source` above. Finally, `process` is the callback. At the end, `process` is called with - one parameter, which is an array of triples formatted according to the [`bfestore`][bfestore]. - It is not necessary to include the `guid` property for each triple; that is added - after the data is returned to the editor. - -Lookups can be created and dynamically loaded at run time. See [configuring -`bfe`][configuring-bfe]. If a 'key' of a dynamically loaded lookup is the same -as a pre-existing/pre-loaded lookup, the pre-loaded one is overwritten and not -used. - - - -[bfestore]: https://github.com/lcnetdev/bfe/blob/master/docs/bfe-api.md#bfestore -[configuring-bfe]: https://github.com/lcnetdev/bfe/blob/master/docs/bfe-api.md#configuring-bfe diff --git a/docs/changelog.md b/docs/changelog.md index c66c3c4..299722c 100755 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -5,6 +5,24 @@ Change Log This change log pertains to builds. ---------------- + +* 1.0.0 (2018-10-18) + * Fixes for labels + * Set rectoBase using env variable; use env.sh to populate + * Updated documentation + +* 0.4.0 (2018-09-24) + * Fixes for #13, #14, #15, #16, #17, #18, #19 + * This release is incorporated into Recto lcnetdev/recto as a submodule. + * Please change the rectoBase variable in static/js/config.js and static/js/config-dev.js to your path. + +* 0.3.1 (2018-03-26) + * Minor profile and code fixes + +* 0.3.0 (2018-03-21) + * LC BIBFRAME 2.0 Pilot version + * Includes BIBFRAME 2.0 Profiles + * 0.2.0 (2015-10-20) * Replace dryice with grunt * Refactor build w/o request.js (deprecated) diff --git a/src/bfe.js b/src/bfe.js index 75bbce4..ad8bf7c 100755 --- a/src/bfe.js +++ b/src/bfe.js @@ -1127,7 +1127,6 @@ bfe.define('src/bfe', ['require', 'exports', 'src/bfestore', 'src/bfelogging', ' $('#bfeditor-cancel', form.form).attr('tabindex', tabIndices++); $('#bfeditor-preview', form.form).click(function () { - var humanized = bfeditor.bfestore.store2text(); var jsonstr = bfeditor.bfestore.store2jsonldExpanded(); // bfeditor.bfestore.store2turtle(jsonstr, humanizedPanel); @@ -1163,7 +1162,7 @@ bfe.define('src/bfe', ['require', 'exports', 'src/bfestore', 'src/bfelogging', ' var $preview = $('
\
\ -
' + humanized + '
\ +
\
\
' + JSON.stringify(jsonstr, undefined, ' ') + '
\
\ diff --git a/src/bfestore.js b/src/bfestore.js index 7c15e22..5ac013f 100755 --- a/src/bfestore.js +++ b/src/bfestore.js @@ -62,20 +62,6 @@ bfe.define('src/bfestore', ['require', 'exports'], function (require, exports) { exports.store2rdfxml = function (jsonld, callback) { exports.store2jsonldnormalized(jsonld, function (expanded) { - /*$.ajax({ - url: config.url + '/profile-edit/server/n3/rdfxml', - type: 'POST', - data: JSON.stringify(expanded), - processData: false, - contentType: 'application/json', - success: function (rdfxml) { - data = new XMLSerializer().serializeToString(rdfxml); - callback(data); - }, - error: function (XMLHttpRequest, status, err) { - console.log(err); - } - });*/ jsonld.toRDF(expanded, { format: 'application/nquads' }, function(err, nquads) { @@ -99,7 +85,6 @@ bfe.define('src/bfestore', ['require', 'exports'], function (require, exports) { } }); turtleWriter.addTriples(turtlestore.getTriples(null, null, null)); - //turtleWriter.addTriples(exports.n3store.getTriples(null, null, null)); turtleWriter.end(function(error, result) { var input = {}; input.n3 = result; @@ -132,11 +117,9 @@ bfe.define('src/bfestore', ['require', 'exports'], function (require, exports) { format: 'N-Quads' }); var store = N3.Store(triples); - // writer.addTriples(store.getTriples(null, null, null, null)); store.getTriples(null, null, null).forEach(function (triple) { writer.addTriple(triple.subject.replace('_bnode', ''), triple.predicate, triple.object.replace('_bnode', ''), graph); }); - // writer.addTriple(" "); writer.end(function (error, nquads) { jsonld.fromRDF(nquads, { format: 'application/nquads' @@ -145,17 +128,7 @@ bfe.define('src/bfestore', ['require', 'exports'], function (require, exports) { }); }); }; - // - // exports.nquads2jsonld = function(nquads){ - // jsonld.fromRDF(nquads, {format:'application/nquads'}, function(err, data) { - // try { - // return exports.jsonld2store(data); - // } catch (err){ - // console.log(err); - // } - // }); - // } - + exports.jsonld2store = function (jsonld) { jsonld.forEach(function (resource) { var s = typeof resource['@id'] !== 'undefined' ? resource['@id'] : '_:b' + guid(); @@ -256,7 +229,7 @@ bfe.define('src/bfestore', ['require', 'exports'], function (require, exports) { } return json; }; - + exports.store2turtle = function (jsonstr, callback) { jsonld.toRDF(jsonstr, { format: 'application/nquads' @@ -344,46 +317,6 @@ bfe.define('src/bfestore', ['require', 'exports'], function (require, exports) { }); }; - exports.store2text = function () { - var nl = '\n'; - var nlindent = nl + '\t'; - var nlindentindent = nl + '\t\t'; - var predata = ''; - var json = exports.store2jsonldExpanded(); - json.forEach(function (resource) { - predata += nl + 'ID: ' + resource['@id']; - if (resource['@type'] !== undefined) { - predata += nlindent + 'Type(s)'; - resource['@type'].forEach(function (t) { - // predata += nlindentindent + t["@id"]; - if (t['@value'] !== undefined) { - predata += nlindentindent + t['@value']; - } else { - predata += nlindentindent + t; - } - }); - } - for (var t in resource) { - if (t !== '@type' && t !== '@id') { - var prop = t.replace('http://id.loc.gov/ontologies/bibframe/', 'bf:'); - prop = prop.replace('http://id.loc.gov/vocabulary/relators/', 'relators:'); - prop = prop.replace('http://id.loc.gov/ontologies/bibframe-lc/', 'bflc:'); - prop = prop.replace('http://rdaregistry.info/termList/', 'rda'); - predata += nlindent + prop; - resource[t].forEach(function (o) { - if (o['@id'] !== undefined) { - predata += nlindentindent + o['@id']; - } else { - predata += nlindentindent + o['@value']; - } - }); - } - } - predata += nl + nl; - }); - return predata; - }; - /** * Generates a GUID string. * @returns {String} The generated GUID.