Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Don't add [] automatically, leave it to the user to set (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Nov 18, 2021
1 parent 6e3d4c4 commit 181d36d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion metafix/src/main/java/org/metafacture/metafix/Metafix.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void emit(final String field, final Value value) {
Value.asList(value, array -> {
final boolean isMulti = array.size() > 1 || value.isArray();
if (isMulti) {
outputStreamReceiver.startEntity(field + "[]");
outputStreamReceiver.startEntity(field);
}

for (int i = 0; i < array.size(); ++i) {
Expand Down
20 changes: 10 additions & 10 deletions metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void doList() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("author[]");
o.get().startEntity("author");
o.get().literal("1", "A UNIVERSITY");
o.get().literal("2", "MAX");
o.get().endEntity();
Expand All @@ -88,7 +88,7 @@ public void doListPathWithDots() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("author[]");
o.get().startEntity("author");
o.get().literal("1", "A UNIVERSITY");
o.get().literal("2", "MAX");
o.get().endEntity();
Expand All @@ -100,9 +100,9 @@ public void doListPathWithDots() {
public void doListWithAppendAndLast() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do list('path': 'creator', 'var': 'c')",
" set_array('author')",
" copy_field('c.name', 'author.$append.name')",
" add_field('author.$last.type', 'Default')",
" set_array('author[]')",
" copy_field('c.name', 'author[].$append.name')",
" add_field('author[].$last.type', 'Default')",
"end",
"remove_field('creator')"),
i -> {
Expand Down Expand Up @@ -149,7 +149,7 @@ public void doListEntitesToLiterals() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("author[]");
o.get().startEntity("author");
o.get().literal("1", "A UNIVERSITY");
o.get().literal("2", "MAX");
o.get().endEntity();
Expand All @@ -161,12 +161,12 @@ public void doListEntitesToLiterals() {
public void doListEntitesToEntities() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do list('path': 'creator.name', 'var': 'c')",
" set_array('author')",
" copy_field('c', 'author.$append.name')",
" set_array('author[]')",
" copy_field('c', 'author[].$append.name')",
" if all_contain('c', 'University')",
" add_field('author.$last.type', 'Organization')",
" add_field('author[].$last.type', 'Organization')",
" else",
" add_field('author.$last.type', 'Person')", //",
" add_field('author[].$last.type', 'Person')", //",
" end",
"end",
"remove_field('creator')"),
Expand Down
18 changes: 9 additions & 9 deletions metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public void ifAny() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Mary");
o.get().literal("2", "A University");
o.get().endEntity();
o.get().literal("type", "Organization");
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Mary");
o.get().literal("2", "Max");
o.get().endEntity();
Expand Down Expand Up @@ -106,14 +106,14 @@ public void ifAll() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Mary");
o.get().literal("2", "A University");
o.get().endEntity();
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Great University");
o.get().literal("2", "A University");
o.get().endEntity();
Expand Down Expand Up @@ -151,15 +151,15 @@ public void ifNone() {
}, (o, f) -> {
o.get().startRecord("1");
o.get().startEntity("author");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Mary");
o.get().literal("2", "A University");
f.apply(2).endEntity();
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("author");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Max");
o.get().literal("2", "Mary");
f.apply(2).endEntity();
Expand Down Expand Up @@ -285,7 +285,7 @@ public void ifAnyMatch() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Some University");
o.get().literal("2", "Filibandrina");
o.get().endEntity();
Expand All @@ -312,14 +312,14 @@ public void ifAllMatch() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Max");
o.get().literal("2", "A University");
o.get().endEntity();
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "Some University");
o.get().literal("2", "University Filibandrina");
o.get().endEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void inline() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "Alohaeha");
o.get().literal("2", "Moin zäme");
o.get().literal("3", "Tach");
Expand All @@ -92,7 +92,7 @@ public void inlineMultilineIndent() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "Alohaeha");
o.get().literal("2", "Moin zäme");
o.get().endEntity();
Expand All @@ -115,7 +115,7 @@ public void inlineDotNotationNested() {
}, (o, f) -> {
o.get().startRecord("1");
o.get().startEntity("data");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "Alohaeha");
o.get().literal("2", "Moin zäme");
o.get().literal("3", "Tach");
Expand Down Expand Up @@ -146,7 +146,7 @@ public void csv() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "Alohaeha");
o.get().literal("2", "Moin zäme");
o.get().literal("3", "Tach");
Expand Down Expand Up @@ -179,7 +179,7 @@ public void tsv() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "Alohaeha");
o.get().literal("2", "Moin zäme");
o.get().literal("3", "Tach");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void upcase() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "MARC");
o.get().literal("2", "JSON");
o.get().endEntity();
Expand All @@ -95,7 +95,7 @@ public void upcaseDotNotationNested() {
}, (o, f) -> {
o.get().startRecord("1");
o.get().startEntity("data");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "MARC");
o.get().literal("2", "JSON");
f.apply(2).endEntity();
Expand Down Expand Up @@ -123,7 +123,7 @@ public void downcase() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "marc");
o.get().literal("2", "json");
o.get().endEntity();
Expand Down Expand Up @@ -154,7 +154,7 @@ public void capitalize() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "Marc");
o.get().literal("2", "Json");
o.get().endEntity();
Expand Down Expand Up @@ -185,7 +185,7 @@ public void substring() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "m");
o.get().literal("2", "j");
o.get().endEntity();
Expand Down Expand Up @@ -217,7 +217,7 @@ public void substringWithVar() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "ma");
o.get().literal("2", "js");
o.get().endEntity();
Expand Down Expand Up @@ -248,7 +248,7 @@ public void trim() {
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("title[]");
o.get().startEntity("title");
o.get().literal("1", "marc");
o.get().literal("2", "json");
o.get().endEntity();
Expand All @@ -270,7 +270,7 @@ public void format() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("number[]");
o.get().startEntity("number");
o.get().literal("1", "41 : 15");
o.get().endEntity();
o.get().endRecord();
Expand All @@ -287,7 +287,7 @@ public void parseText() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("date[]");
o.get().startEntity("date");
o.get().literal("1", "2015");
o.get().literal("2", "03");
o.get().literal("3", "07");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void entitiesPassThroughRepeatNestedEntity() {
o.get().startRecord("1");
o.get().startEntity("deep");
o.get().startEntity("nested");
o.get().startEntity("field[]");
o.get().startEntity("field");
o.get().literal("1", "value1");
o.get().literal("2", "value2");
f.apply(3).endEntity();
Expand Down Expand Up @@ -211,15 +211,15 @@ public void add() {
}, (o, f) -> {
o.get().startRecord("1");
o.get().startEntity("my");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "patrick");
o.get().literal("2", "nicolas");
f.apply(2).endEntity();
o.get().endRecord();

o.get().startRecord("2");
o.get().startEntity("my");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "max");
o.get().literal("2", "patrick");
o.get().literal("3", "nicolas");
Expand All @@ -228,7 +228,7 @@ public void add() {

o.get().startRecord("3");
o.get().startEntity("my");
o.get().startEntity("name[]");
o.get().startEntity("name");
o.get().literal("1", "patrick");
o.get().literal("2", "nicolas");
f.apply(2).endEntity();
Expand Down Expand Up @@ -306,7 +306,7 @@ public void copy() {
public void copyIntoArrayOfStrings() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
// "set_array('author')", <- results in separate objects/entities here
"copy_field('your.name','author.name')",
"copy_field('your.name','author.name[]')",
"remove_field('your')"),
i -> {
i.startRecord("1");
Expand All @@ -329,8 +329,8 @@ public void copyIntoArrayOfStrings() {
@Test
public void copyIntoArrayOfObjects() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('author')",
"copy_field('your.name','author.name')",
"set_array('author[]')",
"copy_field('your.name','author[].name')",
"remove_field('your')"),
i -> {
i.startRecord("1");
Expand All @@ -357,8 +357,8 @@ public void copyIntoArrayOfObjects() {
@Test
public void copyIntoArrayTopLevel() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('author')",
"copy_field('your.name', 'author')",
"set_array('author[]')",
"copy_field('your.name', 'author[]')",
"remove_field('your')"),
i -> {
i.startRecord("1");
Expand Down Expand Up @@ -467,7 +467,7 @@ public void removeEntity() {
@Test
public void setArray() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('foo','a','b','c')"),
"set_array('foo[]','a','b','c')"),
i -> {
i.startRecord("1");
i.endRecord();
Expand Down Expand Up @@ -594,7 +594,7 @@ public void arrayFromHash() {
i.endRecord();
}, o -> {
o.get().startRecord("1");
o.get().startEntity("foo[]");
o.get().startEntity("foo");
o.get().literal("1", "a");
o.get().literal("2", "b");
o.get().literal("3", "c");
Expand Down Expand Up @@ -625,8 +625,8 @@ public void reject() {
@Test
public void appendArray() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('nums', '1')",
"set_array('nums.$append', '2', '3')"),
"set_array('nums[]', '1')",
"set_array('nums[].$append', '2', '3')"),
i -> {
i.startRecord("1");
i.endRecord();
Expand All @@ -644,8 +644,8 @@ public void appendArray() {
@Test
public void mixedArray() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('@context', 'https://w3id.org/kim/lrmi-profile/draft/context.jsonld')",
"set_hash('@context.$append', '@language': 'de')"),
"set_array('@context[]', 'https://w3id.org/kim/lrmi-profile/draft/context.jsonld')",
"set_hash('@context[].$append', '@language': 'de')"),
i -> {
i.startRecord("1");
i.endRecord();
Expand Down

0 comments on commit 181d36d

Please sign in to comment.