Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_elseNested only outputs two hierachy levels #378

Closed
TobiasNx opened this issue Jul 5, 2021 · 7 comments · Fixed by #392
Closed

_elseNested only outputs two hierachy levels #378

TobiasNx opened this issue Jul 5, 2021 · 7 comments · Fixed by #392
Assignees
Labels

Comments

@TobiasNx
Copy link
Contributor

TobiasNx commented Jul 5, 2021

If operating with a file with more than 2 hierachy levels _elseNested reduces this structure to 2 levels:

Input:

<?xml version="1.0" encoding="UTF-8"?>
<records>
	<record>
		<mods>
			<ID>duepublico_mods_00074526</ID>
			<name>
				<type>personal</type>
				<type>simple</type>
				<displayForm>
					<value>Armbruster, André</value>
				</displayForm>
				<role>
					<roleTerm>
						<authority>marcrelator</authority>
						<type>code</type>
						<value>aut</value>
					</roleTerm>
					<roleTerm>
						<authority>marcrelator</authority>
						<type>text</type>
						<value>Author</value>
					</roleTerm>
				</role>
				<nameIdentifier>
					<type>gnd</type>
					<value>1081830107</value>
				</nameIdentifier>
				<namePart>
					<type>family</type>
					<value>Armbruster</value>
				</namePart>
				<namePart>
					<type>given</type>
					<value>André</value>
				</namePart>
			</name>
		</mods>
	</record>
</records>

FLUX:

default infile = FLUX_DIR + "mods.xml";


infile
| open-file
| decode-xml
| handle-generic-xml
| morph(FLUX_DIR + "all.xml")
| encode-xml
| write(FLUX_DIR + "resultNEsted.xml")
;

MORPH:

<?xml version="1.0" encoding="UTF-8"?>
<metamorph xmlns="http://www.culturegraph.org/metamorph" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	version="1">
	<rules>
<data source="_elseNested"/>

</rules>
</metamorph>

OUTPUT:

<?xml version="1.0" encoding="UTF-8"?>
<records>

	<record>
		<ID>
			<value>duepublico_mods_00074526</value>
		</ID>
		<type>
			<value>personal</value>
		</type>
		<type>
			<value>simple</value>
		</type>
		<value>
			<value>Armbruster, André</value>
		</value>
		<authority>
			<value>marcrelator</value>
		</authority>
		<type>
			<value>code</value>
		</type>
		<value>
			<value>aut</value>
		</value>
		<authority>
			<value>marcrelator</value>
		</authority>
		<type>
			<value>text</value>
		</type>
		<value>
			<value>Author</value>
		</value>
		<type>
			<value>gnd</value>
		</type>
		<value>
			<value>1081830107</value>
		</value>
		<type>
			<value>family</value>
		</type>
		<value>
			<value>Armbruster</value>
		</value>
		<type>
			<value>given</value>
		</type>
		<value>
			<value>André</value>
		</value>
	</record>

</records>

If decoded as JSON:

{
	"ID": {
		"value": "duepublico_mods_00074526"
	},
	"type": {
		"value": "personal"
	},
	"type": {
		"value": "simple"
	},
	"value": {
		"value": "Armbruster, André"
	},
	"authority": {
		"value": "marcrelator"
	},
	"type": {
		"value": "code"
	},
	"value": {
		"value": "aut"
	},
	"authority": {
		"value": "marcrelator"
	},
	"type": {
		"value": "text"
	},
	"value": {
		"value": "Author"
	},
	"type": {
		"value": "gnd"
	},
	"value": {
		"value": "1081830107"
	},
	"type": {
		"value": "family"
	},
	"value": {
		"value": "Armbruster"
	},
	"type": {
		"value": "given"
	},
	"value": {
		"value": "André"
	}
}
@TobiasNx TobiasNx added the Bug label Jul 5, 2021
@hagbeck
Copy link
Contributor

hagbeck commented Jul 8, 2021

I can confirm this issue in another case.

<record>
	<contribution>
		<type>Contribution</type>
		<agent>
			<label>Halfbrodt, Michael</label>
			<type>Person</type>
			<gndIdentifier>1038509653</gndIdentifier>
			<id>https://d-nb.info/gnd/1038509653</id>
		</agent>
	</contribution>
</record>

results in

<record>
	<type>
		<value>Contribution</value>
	</type>
	<label>
		<value>Halfbrodt, Michael</value>
	</label>
	<type>
		<value>Person</value>
	</type>
	<gndIdentifier>
		<value>1038509653</value>
	</gndIdentifier>
	<id>
		<value>https://d-nb.info/gnd/1038509653</value>
	</id>
</record>

A solution would be nice.

@TobiasNx TobiasNx added this to Backlog in Metafacture alt Jul 14, 2021
@katauber katauber moved this from Backlog to Ready in Metafacture alt Jul 29, 2021
@TobiasNx
Copy link
Contributor Author

TobiasNx commented Aug 2, 2021

For a possible solution repeated fields/subfields should not be overwritten. flattend is doing this

@dr0i
Copy link
Member

dr0i commented Aug 16, 2021

ping @blackwinter , if you want to have a look

@blackwinter
Copy link
Member

I'd like to, but I don't know when I will find the time...

It might be helpful if someone could prepare a (failing) test case in org.metafacture.metamorph.TestMetamorphBasics.

@TobiasNx
Copy link
Contributor Author

I have set up a sample repo: https://github.com/TobiasNx/notWorkingFlux/tree/main/elseNested_Xml2JSON
@dr0i could create the test from this

@blackwinter
Copy link
Member

I've looked into this a bit over the weekend. Apparently, it's not like this hadn't been anticipated (sort of):

Also, there's the question of nested entities (more than one entity marker in the path), but I won't get into it here...

Originally posted by @blackwinter in #333 (comment)

Oops... 😇

I'll try to come up with a PR in the next couple of days.

blackwinter added a commit that referenced this issue Sep 14, 2021
…ested`).

Keep track of nested entities and open/close them in the appropriate order.

Fixes #378.

Related to #107, #338.
@fsteeg fsteeg moved this from Ready to Review in Metafacture alt Sep 20, 2021
Metafacture alt automation moved this from Review to Done Sep 23, 2021
@blackwinter
Copy link
Member

With _elseNested, entities are only output when an unhandled literal occurs. The issue was that then only the last (current) entity was taken into account. Now all intermediate entities are included as well.

@dr0i dr0i mentioned this issue Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
4 participants