Skip to content

Commit

Permalink
Revert "Change further use of set_array to add_array and set_hash to …
Browse files Browse the repository at this point in the history
…set_hash #374"

This reverts commit aea03a8.
  • Loading branch information
TobiasNx committed Oct 29, 2024
1 parent 840db07 commit ec7f7a3
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 123 deletions.
28 changes: 1 addition & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,6 @@ Options:

#### Record-level functions

##### `add_array`

Creates a new array (with optional values).

```perl
add_array("<targetFieldName>")
add_array("<targetFieldName>", "<value_1>"[, ...])
```

[Example in Playground](https://metafacture.org/playground/?example=add_array)

[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+add_array+{")

##### `add_field`

Creates a field with a defined value.
Expand All @@ -328,19 +315,6 @@ add_field("<targetFieldName>", "<fieldValue>")

[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+add_field+{")

##### `add_hash`

Creates a new hash (with optional values).

```perl
add_hash("<targetFieldName>")
add_hash("<targetFieldName>", "subfieldName": "<subfieldValue>"[, ...])
```

[Example in Playground](https://metafacture.org/playground/?example=add_hash)

[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+add_hash+{")

##### `array`

Converts a hash/object into an array.
Expand Down Expand Up @@ -1053,7 +1027,7 @@ E.g.:
```perl
# "ccm:university":["https://ror.org/0304hq317"]
# "ccm:university_DISPLAYNAME":["Gottfried Wilhelm Leibniz Universität Hannover"]
add_array("sourceOrga[]")
set_array("sourceOrga[]")
do list_as(orgId: "ccm:university[]", orgName: "ccm:university_DISPLAYNAME[]")
copy_field(orgId, "sourceOrga[].$append.id")
copy_field(orgName, "sourceOrga[].$last.name")
Expand Down
32 changes: 16 additions & 16 deletions metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void doList() {
@Test
public void doListExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author')",
"set_array('author')",
"do list('path': 'name', 'var': 'n')",
" upcase('n')",
" trim('n')",
Expand Down Expand Up @@ -212,7 +212,7 @@ public void doListPathWithDots() {
@Test
public void doListPathWithDotsExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author')",
"set_array('author')",
"do list('path': 'some.name', 'var': 'n')",
" upcase('n')",
" trim('n')",
Expand All @@ -237,7 +237,7 @@ public void doListPathWithDotsExplicitAppend() {
@Test
public void doListWithAppendAndLast() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author[]')",
"set_array('author[]')",
"do list('path': 'creator', 'var': 'c')",
" copy_field('c.name', 'author[].$append.name')",
" add_field('author[].$last.type', 'Default')",
Expand Down Expand Up @@ -295,7 +295,7 @@ public void doListEntitesToLiterals() {
@Test
public void doListEntitesToLiteralsExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author')",
"set_array('author')",
"do list('path': 'creator', 'var': 'c')",
" upcase('c.name')",
" trim('c.name')",
Expand All @@ -322,7 +322,7 @@ public void doListEntitesToLiteralsExplicitAppend() {
@Test
public void doListEntitesToEntities() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author[]')",
"set_array('author[]')",
"do list('path': 'creator', 'var': 'c')",
" copy_field('c.name', 'author[].$append.name')",
" if all_contain('c.name', 'University')",
Expand Down Expand Up @@ -359,7 +359,7 @@ public void doListEntitesToEntities() {
@Test
public void wildcardForNestedEntities() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author[]')",
"set_array('author[]')",
"do list('path': 'creator', 'var': 'c')",
" if any_match('c.role.*.roleTerm.*.value','aut|cre')",
" copy_field('c.name', 'author[].$append.name')",
Expand Down Expand Up @@ -430,7 +430,7 @@ public void doListIndexedArray() {
@Test
public void doListIndexedArrayToArrayOfObjects() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author[]')",
"set_array('author[]')",
"do list('path': 'name[]', 'var': 'n')",
" copy_field('n', 'author[].$append.name')",
"end",
Expand Down Expand Up @@ -483,7 +483,7 @@ public void doListIndexedArrayOfObjects() {
@Test
public void doListIndexedArrayOfObjectsExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author')",
"set_array('author')",
"do list('path': 'name[]', 'var': 'n')",
" copy_field('n.name', 'author.$append')",
"end",
Expand All @@ -510,7 +510,7 @@ public void doListIndexedArrayOfObjectsExplicitAppend() {
@Test
public void doListIndexedArrayOfObjectsToArrayOfObjects() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('author[]')",
"set_array('author[]')",
"do list('path': 'name[]', 'var': 'n')",
" copy_field('n.name', 'author[].$append.name')",
"end",
Expand Down Expand Up @@ -670,7 +670,7 @@ public void ifInCollectorCombine() {

private void shouldIterateOverList(final String path, final int expectedCount) {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('trace')",
"set_array('trace')",
"do list(path: '" + path + "', 'var': '$i')",
" add_field('trace.$append', 'true')",
"end",
Expand Down Expand Up @@ -716,7 +716,7 @@ public void shouldIterateOverListWithWildcard() {

private void shouldIterateOverListOfHashes(final String path, final int expectedCount) {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('trace')",
"set_array('trace')",
"do list(path: '" + path + "', 'var': '$i')",
" add_field('trace.$append', 'true')",
"end",
Expand Down Expand Up @@ -771,7 +771,7 @@ public void shouldIterateOverListOfHashesWithWildcard() {
// See https://github.com/metafacture/metafacture-fix/issues/119
public void shouldPerformComplexOperationWithPathWildcard() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('coll[]')",
"set_array('coll[]')",
"do list(path: 'feld?', 'var': '$i')",
" add_field('coll[].$append.feldtest', 'true')",
" copy_field('$i.a.value', 'coll[].$last.a')",
Expand Down Expand Up @@ -847,7 +847,7 @@ public void shouldPerformComplexOperationWithPathWildcard() {
@Test
public void shouldDoListAsWithSingleList() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('sourceOrga[]')",
"set_array('sourceOrga[]')",
"do list_as(orgId: 'ccm:university[]')",
" copy_field(orgId, 'sourceOrga[].$append.id')",
"end"
Expand Down Expand Up @@ -881,7 +881,7 @@ public void shouldDoListAsWithSingleList() {
@Test
public void shouldDoListAsWithMultipleLists() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('sourceOrga[]')",
"set_array('sourceOrga[]')",
"do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]', orgLoc: 'ccm:university_LOCATION[]')",
" copy_field(orgId, 'sourceOrga[].$append.id')",
" copy_field(orgName, 'sourceOrga[].$last.name')",
Expand Down Expand Up @@ -937,9 +937,9 @@ public void shouldDoListAsWithMultipleLists() {
@Test // checkstyle-disable-line JavaNCSS
public void shouldDoListAsWithMultipleListsOfDifferentSizes() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('sourceOrga[]')",
"set_array('sourceOrga[]')",
"do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]', orgLoc: 'ccm:university_LOCATION[]')",
" add_hash('sourceOrga[].$append')",
" set_hash('sourceOrga[].$append')",
" copy_field(orgId, 'sourceOrga[].$last.id')",
" copy_field(orgName, 'sourceOrga[].$last.name')",
" copy_field(orgLoc, 'sourceOrga[].$last.location')",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ public void shouldReportArrayEntityAsArray() {
@Test
public void shouldReportEmptyArrayAsArray() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array(foo)",
"set_array(foo)",
"if is_array(foo)",
" add_field(test,ok)",
"end"
Expand Down Expand Up @@ -1767,7 +1767,7 @@ public void shouldReportEmptyArrayEntityAsEmpty() {
@Test
public void shouldReportEmptyArrayAsEmpty() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array(foo)",
"set_array(foo)",
"if is_empty(foo)",
" add_field(test,ok)",
"end"
Expand Down Expand Up @@ -2127,7 +2127,7 @@ public void shouldReportHashAsObject() {
@Test
public void shouldReportEmptyHashAsObject() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_hash(foo)",
"set_hash(foo)",
"if is_object(foo)",
" add_field(test,ok)",
"end"
Expand Down Expand Up @@ -2499,7 +2499,7 @@ public void shouldMatchString() {
@Test
public void shouldTestMacroVariable() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('type')",
"set_array('type')",
"do put_macro('test')",
" if str_contain('name', 'a$[var]')",
" add_field('type.$append', 'Organization: $[var]')",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void inlineDotNotationNested() {
@Test
public void shouldLookupInternalArrayWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('title', 'Aloha')",
"set_array('title', 'Aloha')",
LOOKUP + " Aloha: Alohaeha)"
),
i -> {
Expand All @@ -162,7 +162,7 @@ public void shouldLookupInternalArrayWithAsterisk() {
@Test
public void shouldLookupDeduplicatedInternalArrayWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('title', 'Aloha', 'Aloha')",
"set_array('title', 'Aloha', 'Aloha')",
"uniq('title')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -182,8 +182,8 @@ public void shouldLookupDeduplicatedInternalArrayWithAsterisk() {
public void shouldNotLookupCopiedInternalArrayWithAsterisk() {
MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected Array or Hash, got String", () ->
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('data', 'Aloha')",
"add_array('title')",
"set_array('data', 'Aloha')",
"set_array('title')",
"copy_field('data', 'title')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -200,8 +200,8 @@ public void shouldNotLookupCopiedInternalArrayWithAsterisk() {
@Test
public void shouldLookupCopiedInternalArrayWithAsteriskExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('data', 'Aloha')",
"add_array('title')",
"set_array('data', 'Aloha')",
"set_array('title')",
"copy_field('data', 'title.$append')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -222,9 +222,9 @@ public void shouldLookupCopiedInternalArrayWithAsteriskExplicitAppend() {
public void shouldNotLookupCopiedDeduplicatedInternalArrayWithAsterisk() {
MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected Array or Hash, got String", () ->
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('data', 'Aloha', 'Aloha')",
"set_array('data', 'Aloha', 'Aloha')",
"uniq('data')",
"add_array('title')",
"set_array('title')",
"copy_field('data', 'title')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -241,9 +241,9 @@ public void shouldNotLookupCopiedDeduplicatedInternalArrayWithAsterisk() {
@Test
public void shouldLookupCopiedDeduplicatedInternalArrayWithAsteriskExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('data', 'Aloha', 'Aloha')",
"set_array('data', 'Aloha', 'Aloha')",
"uniq('data')",
"add_array('title')",
"set_array('title')",
"copy_field('data', 'title.$append')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -263,7 +263,7 @@ public void shouldLookupCopiedDeduplicatedInternalArrayWithAsteriskExplicitAppen
@Test
public void shouldLookupCopiedExternalArrayWithAsteriskExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('title')",
"set_array('title')",
"copy_field('data', 'title.$append')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -285,7 +285,7 @@ public void shouldLookupCopiedExternalArrayWithAsteriskExplicitAppend() {
public void shouldLookupCopiedDeduplicatedExternalArrayWithAsteriskExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"uniq('data')",
"add_array('title')",
"set_array('title')",
"copy_field('data', 'title.$append')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -309,7 +309,7 @@ public void shouldNotLookupMovedDeduplicatedExternalArrayWithAsterisk() {
MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected Array or Hash, got String", () ->
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"uniq('data')",
"add_array('title')",
"set_array('title')",
"move_field('data', 'title')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -329,7 +329,7 @@ public void shouldNotLookupMovedDeduplicatedExternalArrayWithAsterisk() {
public void shouldLookupMovedDeduplicatedExternalArrayWithAsteriskExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"uniq('data')",
"add_array('title')",
"set_array('title')",
"move_field('data', 'title.$append')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -351,7 +351,7 @@ public void shouldLookupMovedDeduplicatedExternalArrayWithAsteriskExplicitAppend
public void shouldNotLookupMovedExternalArrayWithAsterisk() {
MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected Array or Hash, got String", () ->
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('title')",
"set_array('title')",
"move_field('data', 'title')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand All @@ -369,7 +369,7 @@ public void shouldNotLookupMovedExternalArrayWithAsterisk() {
@Test
public void shouldLookupMovedExternalArrayWithAsteriskExplicitAppend() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('title')",
"set_array('title')",
"move_field('data', 'title.$append')",
LOOKUP + " Aloha: Alohaeha)"
),
Expand Down Expand Up @@ -994,9 +994,9 @@ public void shouldLookupInCopiedNestedArraysCreatedWithPrepend() {
private void shouldLookupInCopiedNestedArraysCreatedWith(final String reservedField) {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"put_map('rswk-indicator', s: 'SubjectHeading')",
"add_array('subject[]')",
"add_array('subject[]." + reservedField + ".componentList[]')",
"add_array('subject[].$last.componentList[]." + reservedField + ".type[]')",
"set_array('subject[]')",
"set_array('subject[]." + reservedField + ".componentList[]')",
"set_array('subject[].$last.componentList[]." + reservedField + ".type[]')",
"do list(path: 'D', 'var': '$i')",
" copy_field('$i', 'subject[].$last.componentList[].$last.type[]." + reservedField + "')",
"end",
Expand Down Expand Up @@ -1247,7 +1247,7 @@ public void shouldExplicitLookupRdfUrlWithRedirection() {
@Test // Scenario 1
public void shouldLookupInExternalRdfMapGetObjectOfSubjectWithTargetedPredicateOfSpecificLanguage() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('prefLabel', 'https://w3id.org/kim/hochschulfaechersystematik/n4')",
"set_array('prefLabel', 'https://w3id.org/kim/hochschulfaechersystematik/n4')",
"put_rdfmap('" + RDF_MAP + "', 'rdfmap', target: 'skos:prefLabel', select_language: 'de')",
"lookup('prefLabel.*', 'rdfmap')"
),
Expand All @@ -1266,7 +1266,7 @@ public void shouldLookupInExternalRdfMapGetObjectOfSubjectWithTargetedPredicateO
@Test // Scenario 2
public void shouldLookupInExternalRdfMapGetSubjectWithTargetedPredicateOfSpecificLanguage() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('id', 'Mathematics, Natural Sciences')",
"set_array('id', 'Mathematics, Natural Sciences')",
"put_rdfmap('" + RDF_MAP + "', 'rdfmap', target: 'skos:prefLabel', select_language: 'en')",
"lookup('id.*', 'rdfmap')"
),
Expand Down Expand Up @@ -1408,7 +1408,7 @@ public void shouldLookupRdfDefinedPropertyToSubject() {

private void shouldLookupInExternalRdfMapGetObjectWithTargetedPredicateOfSpecificLanguage(final String target) {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_array('prefLabel', 'Mathematics, Natural Sciences')",
"set_array('prefLabel', 'Mathematics, Natural Sciences')",
"put_rdfmap('" + RDF_MAP + "', 'rdfmap', target: '" + target + "', select_language: 'de')",
"lookup('prefLabel.*', 'rdfmap')"
),
Expand Down
Loading

0 comments on commit ec7f7a3

Please sign in to comment.