alpheios-project / morph-client

Morphology Client Library Interface
ISC License
0 stars 1 forks source link

need to carry credits and source information along with morphology service output #2

Closed balmas closed 6 years ago

balmas commented 6 years ago

we need to provide credits for morphological information along with the data returned by the analysis services. these will contain information about the engine used to do the analysis and copyright or other credit information.

Possibly we want a general purpose data structure for this as other libraries may need it as well -- such as dictionary client adapter, etc.

getHomonym (see #1) then would return an object that wrapped the Homonym, not just the homonym itself.

balmas commented 6 years ago

per discussion with @kirlat I'll experiment with implementing a provider object which can be included or linked to from the homonym rather than the wrapper approach

balmas commented 6 years ago

@kirlat, I'd like a review from you on what I've prototyped using a JSProxy. A key driver behind this approach is that individual properties of an alpheios data model object (such as a Lexeme) may be populated by different sources at different times. So we can't always know when we construct an object who will provide all of its properties, or whether there will be multiple different providers.

I've created a general purpose ResourceProvider class: https://github.com/alpheios-project/data-models/blob/providerobj/src/resource_provider.js

It has a static method which can be used to construct a simple JSProxy which proxies access to a ResourceProvider for an object:

static getProxy (provider = null, target = {}) {
    return new Proxy(target, {
      get: function (target, name) {
        return name === 'provider' ? provider : target[name]
      }
    })
  }

Creating a new proxied data object looks like:

let provider =  new Models.ResourceProvider(providerUri, providerRights)
let lexmodel = new Models.Lexeme(lemma, inflections, shortdef)
let providedLexeme = Models.ResourceProvider.getProxy(provider, lexmodel)

And client code adding a new provider for a property of a Lexeme:

 if (! lex.meaning) {
   lexClient.lookupShortDef(lex.lemma).then((result) => {
   lex.meaning = 
   if (lex.meaning.provider !== lemma.provider) {
    // do something to display the different provider
   }
  })
}

I think this approach allows us to not to have to change our data model classes to know in advance which ones are going to have providers for their data and which are not, and also gives us the flexibility to change how we represent the resource provider without impacting the objects which reference them.

A full example of how this can be used in the client can be found in my wordsvc prototype embedded library: https://github.com/alpheios-project/wordsvc/blob/master/src/controller.js

The branches of code this can be found in: https://github.com/alpheios-project/tufts-adapter/compare/providerobj?expand=1 https://github.com/alpheios-project/data-model/compare/providerobj?expand=1 https://github.com/alpheios-project/lexicon-client/tree/master

balmas commented 6 years ago

ok this is what's implemented now. closing.