[Metafacture] RE:Metamorph: compare two values

Prongué Nicolas (HES) nicolas.prongue at hesge.ch
Thu Apr 2 15:38:31 CEST 2015


Thank you for your help, Christoph!

I could solve my problem with the 'unique'-function and by using a 'data'-collector that collects more than one value.

Here my example for the comparison of language code appearing in MARC field 008 _and_ in MARC field 041$a:

<data source="008" name="@lang" >
	<substring start="35" end="38" />
</data>
<entity name="dct:language" >
	<data source="041*.a|@lang" name="~rdf:resource" >
		<trim />
		<unique part="value" />
		<lookup in="languages" />
	</data>
</entity>

I wish you a nice Easter break.
Nicolas

________________________________________
De : Böhme, Christoph [C.Boehme at dnb.de]
Envoyé : vendredi 27 mars 2015 17:53
À : Prongué Nicolas (HES); metafacture at lists.dnb.de
Objet : AW: Metamorph: compare two values

Dear Nicolas,

conditional processing can be achieved with the <if>-statement which can be used in all collectors. Now, we need to find a way to compare two values within the if-statement. For this we first need to find a way to collect both values in one Metamorph statement so that  we can apply a function or collector to them. Generally, you collect multiple values in Metamorph in two ways:

1. Obviously, you can use a collector (such as concat or combine) to collect data from different
   sources (such as different fields)
2. Another way is to use a data statement which uses a pattern to define its sources so that it receives
   multiple data items over time. In functions you can then work with these "time series" of data.

Once, we have collected the two values with one of the two methods we can compare them. For collectors there is an equalsTo-collector which compares all received values and outputs them only if they are equal. For the exact behaviour of the collector, I advise you to have a look at the source code. There may be some quirks in the logic of the collector due to the requirements we had, when we introduced it originally.  To achieve a not-equals-to comparison, you wrap the equalsTo-collector in a none-statement which inverts its meaning (use flushWith on the none-statement to specify when the comparison is completed)

With the data-statement approach we can use a trick to do the comparison. The unique-function is a stateful function which filters duplicate values and outputs each value only once. By combing this function with the occurrence-function you can output a value only if you received two values which means they are different. This would look something like this:

<data source="sourceA|sourceB" name="isnotequal">
  <unique part="value" />
  <occurrence only="2" />
</data>

I think, you can use flushWith and reset attributes on unique and occurrence to specify the range within which the values are supposed to be not equal.

Hope this helps!

Best,
Christoph



Von: metafacture-bounces at lists.dnb.de [mailto:metafacture-bounces at lists.dnb.de] Im Auftrag von Prongué Nicolas (HES)
Gesendet: Mittwoch, 25. März 2015 10:47
An: metafacture at lists.dnb.de
Betreff: [Metafacture] Metamorph: compare two values

Dear list,

I am working on the transformation of swiss bibliographic data with the Metamorph language (Swissbib project). Here is my question:

Is it possible to compare 2 values in the source fields (in this case MARC/XML-subfields) and then to apply a rule only if these values are equal (or not) ?
Example: I have a language code in field 008, I have another language code in field 041. I would like to use both of them only if they are not the same…

Do you have an idea of how to do that?

Thanks for your help

Nicolas Prongué
__________________________________
Nicolas Prongué ▪ assistant de recherche et d’enseignement
Haute école de gestion de Genève, Département Information documentaire
Battelle ▪ Bâtiment F ▪ Rte de Drize 7 ▪ CH-1227 Carouge
+41 22 388 18 76



More information about the Metafacture mailing list