{"id":13558203,"url":"https://github.com/curationexperts/qa-ldf","last_synced_at":"2025-04-03T12:32:03.087Z","repository":{"id":52168870,"uuid":"79062682","full_name":"curationexperts/qa-ldf","owner":"curationexperts","description":"Providies bindings from Questioning Authority to the linked data caching fragment server for fast query of RDF-based authorities.","archived":false,"fork":false,"pushed_at":"2017-08-17T19:24:01.000Z","size":628,"stargazers_count":3,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T23:06:38.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/curationexperts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-15T22:06:39.000Z","updated_at":"2017-04-11T18:43:16.000Z","dependencies_parsed_at":"2022-08-20T23:40:51.750Z","dependency_job_id":null,"html_url":"https://github.com/curationexperts/qa-ldf","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curationexperts%2Fqa-ldf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curationexperts%2Fqa-ldf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curationexperts%2Fqa-ldf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curationexperts%2Fqa-ldf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/curationexperts","download_url":"https://codeload.github.com/curationexperts/qa-ldf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247002583,"owners_count":20867483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:04:48.460Z","updated_at":"2025-04-03T12:31:59.975Z","avatar_url":"https://github.com/curationexperts.png","language":"Ruby","readme":"QuestioningAuthority::LDF\n=========================\n[![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)\n\nThis sofware providies bindings from [Questioning Authority](https://github.com/projecthydra-labs/questioning_authority) to the [linked data caching fragment server](https://github.com/ActiveTriples/linked-data-fragments) for fast query of RDF-based authorities.\n\nWhat Does This Do?\n------------------\n\nThis gem offers a caching version of the [Questioning Authority](https://github.com/projecthydra-labs/questioning_authority) interface relying on the ActiveTriples LDF caching service. A set of linked data \"authorities\" are exposed through the Questioning Authority API, and cached for fast recall using the Linked Data Fragments Caching Server. Models on the Hydra/Rails side are provided to handle caching and easy presentation of labels.\n\nBoth the QA and LDF APIs are available in mountable forms, so they can run directly in your Hydra application---see below for details.\n\n### Why use this?\n\nThe main reason you may be interested in this software is to handle local caching of linked data references in your metadata.\n\n### Upcoming features include:\n\n  - Support for `Qa::Authority::Base#all` for all LDF authorities through [Hydra Core Partial Collection View](http://www.hydra-cg.com/spec/latest/core/#hydra:PartialCollectionView) style paging.\n  - A default search, accessing only cached items.\n\nHow Does it Work?\n-----------------\n\n### [TK] Architecture Overview.\n\n### Mounting and configuring the LDF caching server\n\nThe LDF caching server can run as a mounted application within Rails. To use the caching server, add the following to your `Gemfile`:\n\n```ruby\ngem 'qa-ldf', '~\u003e0.3.0'\n\n# for now use the active branch of the linked data caching fragment server\ngem 'ld_cache_fragment', github: 'ActiveTriples/linked-data-fragments', branch: 'feature/multi-dataset'\n```\n\nThen you need to mount the application to an unused route:\n\n```ruby\n# config/routes.rb\n\nRails.application.routes.draw do\n  # ...\n  mount LinkedDataFragments::CacheServer::APPLICATION =\u003e '/ldcache'\n  # ...\nend\n```\nAnd add an `ldf.yml` configuration.\n\n```yaml\n# config/ldf.yml\ndevelopment:\n  uri_endpoint: 'http://localhost:3000/ldcache/{?subject}'\n  uri_root: 'http://localhost:3000/ldcache'\n  cache_backend:\n    provider: 'repository'\ntest: \u0026TEST_\n  uri_endpoint: 'http://localhost:3000/ldcache/{?subject}'\n  uri_root: 'http://localhost:3000/ldcache'\n  cache_backend:\nprovider: 'repository'\n  production:\n  uri_endpoint: 'http://localhost:3000/ldcache/{?subject}'\n  uri_root: 'http://localhost:3000/ldcache'\n  cache_backend:\n    provider: 'marmotta'\n```\n\nYou should now be able to access the ldcache endpoint at `http://example.com/ldcache`. That address will return a dataset description for the root dataset. Queries sent to that endpoint access the transparent cache. For example:\n\n    http://example.com/ldcache/?subject=http://id.loc.gov/authorities/subjects/sh2004002556\n\nwill pass the request through to the Library of Congress on the first request, subsequent requests are retrieved from the cached.\n\nFinally, configure `Qa::LDF` to aim at the cache server:\n\n```ruby\nQa::LDF.configure!(endpoint: LinkedDataFragments::Settings.uri_root)\n```\n\nIn a Hydra app, the best place to put this is in an initializer, e.g. `config/initializers/hydra_config.rb`.\n\n#### Datasets\n\nThe cache server uses [RDF Datasets](http://www.hydra-cg.com/spec/latest/linked-data-fragments/#datasets) to manage sperate cache spaces. The root dataset is at the server root (`http://example.com/ldcache`, above), and additional datasets are available at any `dataset/*` path following from the root. The `Qa::LDF` authorities are configured to use independent datasets, so each authority corresponds to a cache space of its own. Each dataset provides its own description at its base path, and is queryable with `?subject=` queries as demonstrated above.\n\n#### Selecting a Triplestore Backend\n\nThe caching server provides several backends for persistent storage, we recommend using the Marmotta backend, but a Blazegraph backend (untested with this gem) is also provided. Read the [ActiveTriples::LinkedDataFragments documentation on backend configuration](https://github.com/ActiveTriples/linked-data-fragments#configuration) for more.\n\n#### LDF caching as an external service.\n\nThe LDF caching server can run independently from your Hydra application as a lightweight, generic [Rack](http://www.rubydoc.info/github/rack/rack/file/SPEC) application, or as a standalone Rails app. You may want to deploy the server in this way so it can run on separate hardware, or to segregate Linked Data \"follow your nose\" network traffic.\n\nThe simplest way to get a working application that will run on any Rack-compatible server is to create a `./config.ru` containing:\n\n```ruby\n# ./config.ru\nrequire 'ld_cache_fragment/cache_server'\n\nrun LinkedDataFragments::CacheServer::APPLICATION\n```\n\nWith this in your working directory, you can run `$ rackup` to launch a basic server. More robust deployments are possible using servers like [Puma](https://github.com/puma/puma#rackup).\n\n#### [TK] LDF caching as a Rails app\n\nAuthority Sources\n----------------------\n\n### LCNAF\n\nA caching interface to the Library of Congress Name Authority File is implemented as a QA authority as `Qa::LDF::LCNames`. This uses the same search code deployed by the generic LC authorities provided by QA, but provides `id.loc.gov` results. This authority is aliased to `Qa::Lcnames` pending closure of https://github.com/projecthydra-labs/questioning_authority/issues/137. It is available at the endpoint `authorities/search/lcnames`.\n\n### FAST\n\nA similar interface to FAST (Faceted Application of Subject Terminology) is in `Qa::LDF::FAST`. This authority is aliased to `Qa::Fast`, and is available at `authorities/search/fast`.\n\nConfiguring authorities\n-----------------------\n\n### [TK] Models.\n\n### Forms\n\nAutocomplete handling for Questioning Authority is provided by Sufia/Hyrax. To this handling, we add a custom dropdown for selecting from multiple authorities in a field.\n\n# Hyrax Autocomplete\n\nYou've got a `Work` in Hyrax and it has a `Creator` field. Wouldn't it be nice to have autocomplete on that form with a controlled vocabulary? Hyrax has this functionality, but you need to set some things up first.\n\nThe most basic way a field is associated with a particular autocomplete data source is with a data attribute on the element. The `data-autocomplete-url` attribute stores a path to the data source. To add one to an existing field create a partial for the field in `app/views/records/edit_fields/`.\n\nIn the partial, specify the data source:\n\n```erb\n\u003c%=\n  f.input key,\n  as: :multi_value,\n  input_html: {\n  class: 'form-control',\n  data: { 'autocomplete-url' =\u003e \"/authorities/search/loc/names\",\n          'autocomplete' =\u003e key }\n        } ,\n  required: f.object.required?(key) %\u003e\n```\n\nHyrax comes with [Questioning Authority](https://github.com/projecthydra-labs/questioning_authority) which provides some RESTful endpoints that you can use as autocomplete sources. Checkout the QA README for a list of the authorities that it comes with (you can even make your own).\n\nWhen the Hyrax form for your `Work` loads the autocomplete JavaScript is initialized for certain fields. For the `Creator` field that we created a partial for, all we needed to was add the data attribute and the autocomplete is activated.\n\nIf the field is not one of the default fields, you'll need to run this to activate autocomplete on the field:\n\n```js\nvar Autocomplete = require('hyrax/autocomplete');\nvar autocomplete = new Autocomplete({\n  \"autocompleteFields\":\n    [\"subject\",\"language\",\"creator\",\"based_near\",\"work\"]\n  });\n$('.multi_value.form-group').manage_fields({\n  add: function(e, element) {\n    autocomplete.fieldAdded(element)\n  }\n});\nautocomplete.setup();\n```\n\nYou just need to pass the fields when creating an Autocomplete instance.\n\nAutocomplete in Hyrax currently uses jQuery UI Autocomplete. Hyrax stores the [jQuery UI Autocomplete options and source](http://jqueryui.com/autocomplete/#remote-jsonp) in ES6 classes. Unless you need to make specific query that requires you to change the options and source, the JS will use a default query from [default.es6](https://github.com/projecthydra-labs/hyrax/blob/master/app/assets/javascripts/hyrax/autocomplete/default.es6). This should just work with the QA vocabs.\n\nThe autocomplete for the `Work` field requires different a different source and options so it has a different class: [work.es6](https://github.com/projecthydra-labs/hyrax/blob/master/app/assets/javascripts/hyrax/autocomplete/work.es6).\nAfter creating your own class, you will need to import it and an additional case to the autocomplete method in [autocomplete.es6](https://github.com/projecthydra-labs/hyrax/blob/master/app/assets/javascripts/hyrax/autocomplete.es6)\n\n#### Adding Controlled Vocabulary Dropdown Options\n\nTo create your own dropdown with authorities you extend the `QASelectService` class. By convention, we place this in `app/services`.\n\n```ruby\n# app/services/name_authorities.rb\nclass NameAuthorities \u003c QaSelectService\n  def initialize\n    super('names')\n  end\nend\n```\n\nInitialize the service with the name of a YAML file `names.yml` that contains a list of authorities:\n\n```yaml\nterms:\n  - id: /authorities/search/loc/names\n    term: LOC Names\n    active: true\n  - id: /authorities/search/assign_fast/all\n    term: FAST\n    active: true\n```\n\nThen in the partials for the input field at `app/views/records/edit_fields/_creator.html.erb`:\n\n```erb\n\u003c% name_authorities = Hyrax::NameAuthorities.new %\u003e\n\n\u003c%=\n  f.input key,\n    as: :multi_value,\n    input_html: {\n      class: 'form-control',\n      data: { 'autocomplete-url' =\u003e name_authorities.select_active_options.first.last,\n              'autocomplete' =\u003e key } } ,\n      required: f.object.required?(key) %\u003e\n\n\u003c%= f.input key, collection: name_authorities.select_active_options, label: false %\u003e\n```\n\nImplementing Custom Authorities\n-------------------------------\n\nCustom (local) authorities can be included by placing a YAML configuration in `config/authorities`. This configuration should specific a list of terms, and give an `id`, `term` name, and `active` flag for each of them. Terms can be set `inactive` to disable them.\n\n```yaml\n# config/authorities/moomin_valley.yml\nterms:\n  - id:      http://example.com/moomin\n    term:   'Moomin'\n    active: true\n  - id:      http://example.com/moomin_papa\n    term:   'Moomin Papa'\n    active: true\n  - id:      http://example.com/moomin_mama\n    term:   'Moomin Mama'\n    active: true\n  - id:      http://example.com/snorkmaiden\n    term:   'Snorkmaiden'\n    active: true\n```\n\nThese terms are now available from Questioning Authority at `/authorities/search/local/moomin_valley'.\n\nLicense\n-------\n\nThis software is available under the \u003ca href=\"https://raw.githubusercontent.com/curationexperts/qa-ldf/master/LICENSE\"\u003eApache 2.0 License\u003c/a\u003e.\n\nAcknowledgements\n----------------\n\n\u003ca href=\"https://www.chemheritage.org/\" \u003e\n\u003cimg src=\"https://raw.githubusercontent.com/curationexperts/qa-ldf/1e09875605fa979a2981cc6a5c5f823b935530a3/readme_logos/CHF_logo_primary_tagline.jpg\" width=\"25%\"\u003e\u003c/a\u003e\n\u003c/br\u003e\n\u003ca href=\"https://www.imls.gov/\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/curationexperts/qa-ldf/1e09875605fa979a2981cc6a5c5f823b935530a3/readme_logos/imls_logo_2c.jpg\" width=\"25%\"\u003e\u003c/a\u003e\n\nThis project was made possible in part by the Institute of Museum and Library Services grant SP-02-16-0014-16.\n","funding_links":[],"categories":["Ruby","others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcurationexperts%2Fqa-ldf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcurationexperts%2Fqa-ldf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcurationexperts%2Fqa-ldf/lists"}