AW: [Metafacture] implementation of new morph functions

Böhme, Christoph C.Boehme at dnb.de
Tue Mar 24 08:50:15 CET 2015


Hi Günter,

the extensibility of Metamorph is a bit limited as it is currently not possible to extend the schema. As a workaround you could use the java-function which allows you to use any Java class that implements the Function interface as a function. It would look like this in Metamoprh:

<data source=”blabla”>
   <java class=”fully.qualified.classname.to.FunctionClass” aParameter=”ABC” anotherParameter=”def” />
</data>

The attributes are mapped to setters of the same name. This works exactly like a function defined in the schema except that it looks ugly with the fully qualified java class name in the attribute ☺

It would be really cool to be able to add new functionality to Metamorph properly by extending the schema. I think it should not be too complicated. There are just two problems that need to be solved:
1. The schema need to be adapted so that can be extended. I reckon that best way to do this is with a substitution group for the functions (and optionally the collectors). New elements can be added to these groups in derived schemas (I have not looked into this in detail, so there might be some caveats). I found the book “XML Schema” by Eric van der Vlist quite helpful when working with XML Schema in the past.
2. Metamorph need to be made aware of the derived schema (in fact of the derived schemata as there might be more than one extension package). I have yet not thought about this point. There might be a way with Java XML use more than one schema for validation. However, a quick search seems to not confirm this, as the first hit on Google suggest to automatically generate a parent schema which includes the other ones see [1].

If you are interested in making the Metamorph schema extensible, that would be great!

Best,
Christoph

[1] https://stackoverflow.com/questions/1094893/validate-an-xml-file-against-multiple-schema-definitions



Von: metafacture-bounces at lists.dnb.de [mailto:metafacture-bounces at lists.dnb.de] Im Auftrag von Günter Hipler
Gesendet: Montag, 23. März 2015 23:43
An: metafacture at lists.dnb.de
Cc: Sebastian Schüpbach
Betreff: [Metafacture] implementation of new morph functions

Hi,

I want to implement additional morph functions in my own repository and deploy them AS packaged jar-files

There is a nice procedure with flux commands which are loaded as plugins when they are part of the plugins directory in the metafacture-runner repository. The only thing to be done is to write  an additional flux-commands.properties file with the new commands.



Metamorph functions in contrast have to be defined in the metamorph.xsd schema (    <group name="function">) part of the metafacture-core repository.
An additional morph-functions.properties file isn't enough. I get errors like:

Exception in thread "main" org.culturegraph.mf.exceptions.MetafactureException: class org.culturegraph.mf.morph.Metamorph could not be instantiated
<snip....>
Caused by: org.culturegraph.mf.exceptions.MorphDefException: Error during DOM creation: Error parsing xml: cvc-complex-type.2.4.a: Invalid content was found starting with element 'itemLink'. One of '{"http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:compose, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:regexp, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:replace, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:substring, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:lookup, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:whitelist, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:blacklist, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:isbn, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:equals, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:not-equals, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:case, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:timestamp, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:dateformat, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:htmlanchor, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:trim, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:split, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:normalize-utf8, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:occurrence, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:constant, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:count, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:urlencode, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:buffer, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:name, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:switch-name-value, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:unique, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:script, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:setreplace, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:java}' is expected.
    at org.culturegraph.mf.util.xml.DomLoader$TransformerErrorHandler.handle(DomLoader.java:215)
    at org.culturegraph.mf.util.xml.DomLoader$TransformerErrorHandler.error(DomLoader.java:205)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.postErrorToListener(TransformerImpl.java:811)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:754)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:359)
    at org.culturegraph.mf.util.xml.DomLoader.parse(DomLoader.java:113)
    at org.culturegraph.mf.morph.AbstractMetamorphDomWalker.walk(AbstractMetamorphDomWalker.java:109)
    at org.culturegraph.mf.morph.AbstractMetamorphDomWalker.walk(AbstractMetamorphDomWalker.java:105)
    at org.culturegraph.mf.morph.Metamorph.<init>(Metamorph.java:163)
    at org.culturegraph.mf.morph.Metamorph.<init>(Metamorph.java:108)
    at org.culturegraph.mf.morph.Metamorph.<init>(Metamorph.java:98)
    at org.culturegraph.mf.morph.Metamorph.<init>(Metamorph.java:94)
    ... 15 more
Caused by: javax.xml.transform.TransformerException: Error parsing xml: cvc-complex-type.2.4.a: Invalid content was found starting with element 'itemLink'. One of '{"http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:compose, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:regexp, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:replace, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:substring, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:lookup, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:whitelist, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:blacklist, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:isbn, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:equals, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:not-equals, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:case, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:timestamp, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:dateformat, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:htmlanchor, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:trim, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:split, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:normalize-utf8, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:occurrence, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:constant, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:count, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:urlencode, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:buffer, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:name, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:switch-name-value, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:unique, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:script, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:setreplace, "http://www.culturegraph.org/metamorph"<http://www.culturegraph.org/metamorph>:java}' is expected.
    ... 25 more


At the moment I can't see a possibility to extend the metamorph.xsd in my extensions without changing the original schema and compiling the metafacture-core by my own.

Any suggestions?


Günter


--

UNIVERSITÄT BASEL

Universitätsbibliothek

Günter Hipler

Projekt swissbib

Schönbeinstrasse 18-20

4056 Basel, Schweiz

Tel.: +41 61 267 31 12

Fax: +41 61 267 31 03

E-Mail guenter.hipler at unibas.ch<mailto:guenter.hipler at unibas.ch>

URL www.swissbib.org<http://www.swissbib.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.dnb.de/pipermail/metafacture/attachments/20150324/054264a0/attachment.html


More information about the Metafacture mailing list