-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
176 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/LanguageTagChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.gwdg.metadataqa.api.rule.singlefieldchecker; | ||
|
||
import de.gwdg.metadataqa.api.counter.FieldCounter; | ||
import de.gwdg.metadataqa.api.json.DataElement; | ||
import de.gwdg.metadataqa.api.model.XmlFieldInstance; | ||
import de.gwdg.metadataqa.api.model.selector.Selector; | ||
import de.gwdg.metadataqa.api.rule.RuleCheckerOutput; | ||
import de.gwdg.metadataqa.api.rule.RuleCheckingOutputStatus; | ||
import de.gwdg.metadataqa.api.rule.RuleCheckingOutputType; | ||
import de.gwdg.metadataqa.api.uniqueness.UniquenessExtractor; | ||
|
||
import java.util.List; | ||
|
||
public class LanguageTagChecker extends SingleFieldChecker { | ||
private static final long serialVersionUID = 7236047216814906713L; | ||
public static final String PREFIX = "languageTag"; | ||
|
||
public LanguageTagChecker(DataElement field) { | ||
this(field, field.getLabel()); | ||
} | ||
|
||
public LanguageTagChecker(DataElement field, String header) { | ||
super(field, header); | ||
} | ||
|
||
@Override | ||
public void update(Selector cache, FieldCounter<RuleCheckerOutput> results, RuleCheckingOutputType outputType) { | ||
if (isDebug()) | ||
LOGGER.info(this.getClass() + " " + this.id); | ||
var allPassed = true; | ||
var isNA = true; | ||
List<XmlFieldInstance> instances = cache.get(field); | ||
if (instances != null && !instances.isEmpty()) { | ||
for (XmlFieldInstance instance : instances) { | ||
if (instance.hasLanguage()) { | ||
isNA = false; | ||
if (isDebug()) | ||
LOGGER.info("language tag: " + instance.hasLanguage()); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
addOutput(results, isNA, allPassed, outputType); | ||
if (isDebug()) | ||
LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed)); | ||
|
||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MultilingualChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package de.gwdg.metadataqa.api.rule.singlefieldchecker; | ||
|
||
import de.gwdg.metadataqa.api.counter.FieldCounter; | ||
import de.gwdg.metadataqa.api.json.DataElement; | ||
import de.gwdg.metadataqa.api.model.XmlFieldInstance; | ||
import de.gwdg.metadataqa.api.model.selector.Selector; | ||
import de.gwdg.metadataqa.api.rule.RuleCheckerOutput; | ||
import de.gwdg.metadataqa.api.rule.RuleCheckingOutputStatus; | ||
import de.gwdg.metadataqa.api.rule.RuleCheckingOutputType; | ||
import de.gwdg.metadataqa.api.uniqueness.UniquenessExtractor; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class MultilingualChecker extends SingleFieldChecker { | ||
private static final long serialVersionUID = 3911175767180059821L; | ||
public static final String PREFIX = "multilingual"; | ||
|
||
public MultilingualChecker(DataElement field) { | ||
this(field, field.getLabel()); | ||
} | ||
|
||
public MultilingualChecker(DataElement field, String header) { | ||
super(field, header); | ||
} | ||
|
||
@Override | ||
public void update(Selector cache, FieldCounter<RuleCheckerOutput> results, RuleCheckingOutputType outputType) { | ||
if (isDebug()) | ||
LOGGER.info(this.getClass() + " " + this.id); | ||
var allPassed = true; | ||
var isNA = true; | ||
Set<String> languages = new HashSet<>(); | ||
List<XmlFieldInstance> instances = cache.get(field); | ||
if (instances != null && !instances.isEmpty()) { | ||
for (XmlFieldInstance instance : instances) { | ||
if (instance.hasLanguage()) { | ||
languages.add(instance.getLanguage()); | ||
isNA = false; | ||
} | ||
} | ||
} | ||
if (languages.size() < 2) | ||
allPassed = false; | ||
|
||
addOutput(results, isNA, allPassed, outputType); | ||
if (isDebug()) | ||
LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"id":"1","description":[{"@lang":"de","#value":"Portr\u00e4t"},{"@lang":"zh","#value":"\u8096\u50cf"}]} |
11 changes: 11 additions & 0 deletions
11
src/test/resources/configuration/schema/rules/hasLanguageTag.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
format: json | ||
fields: | ||
- name: about | ||
path: $.['about'] | ||
rules: | ||
- lessThanOrEquals: description | ||
- name: description | ||
path: $.['description'] | ||
asLanguageTagged: true | ||
rules: | ||
- hasLanguageTag: true |
11 changes: 11 additions & 0 deletions
11
src/test/resources/configuration/schema/rules/isMultilingual.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
format: json | ||
fields: | ||
- name: about | ||
path: $.['about'] | ||
rules: | ||
- lessThanOrEquals: description | ||
- name: description | ||
path: $.['description'] | ||
asLanguageTagged: true | ||
rules: | ||
- isMultilingual: true |