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

589-fixRunnerExamples #654

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @author Markus Michael Geipel
*
*/
@Description("Expands some macros for RDF/XML")
@Description("Expands some macros for RDF/XML. When using Fix, configure `referenceMarker` to any char but the default `*`")
@In(StreamReceiver.class)
@Out(StreamReceiver.class)
@FluxCommand("rdf-macros")
Expand All @@ -41,6 +41,8 @@ public final class RdfMacroPipe extends DefaultStreamPipe<StreamReceiver> {
public static final String RDF_ABOUT = "~rdf:about";
public static final String XML_LANG = "~xml:lang";
private String autoAddedSubject = "";
private char referenceMarker = REFERENCE_MARKER;
private char languageMarker = LANGUAGE_MARKER;

/**
* Creates an instance of {@link RdfMacroPipe}.
Expand All @@ -57,6 +59,42 @@ public void setAutoAddedSubject(final String autoAddedSubject) {
this.autoAddedSubject = autoAddedSubject;
}

/**
* Sets the single char reference marker.
*
* @param referenceMarker the reference marker
*/
public void setReferenceMarker(final String referenceMarker) {
this.referenceMarker = referenceMarker.charAt(0);
}

/**
* Gets the reference marker.
*
* @return the reference marker
*/
public char getReferenceMarker() {
return referenceMarker;
}

/**
* Sets the single char language marker.
*
* @param languageMarker the language marker
*/
public void setLanguageMarker(final String languageMarker) {
this.languageMarker = languageMarker.charAt(0);
}

/**
* Gets the language marker.
*
* @return the language marker
*/
public char getLanguageMarker() {
return languageMarker;
}

@Override
public void startRecord(final String identifier) {
getReceiver().startRecord(identifier);
Expand Down Expand Up @@ -87,8 +125,8 @@ public void endEntity() {

@Override
public void literal(final String name, final String value) {
final int index = name.indexOf(LANGUAGE_MARKER);
if (!name.isEmpty() && name.charAt(0) == REFERENCE_MARKER) {
final int index = name.indexOf(languageMarker);
if (!name.isEmpty() && name.charAt(0) == referenceMarker) {
getReceiver().startEntity(name.substring(1));
getReceiver().literal(RDF_REFERENCE, value);
getReceiver().endEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ as-lines|
catch-object-exception|
decode-pica|
batch-log(batchsize="100000")|
morph(FLUX_DIR + "extract.xml", *)|
fix(FLUX_DIR + "extract.fix", *)|
stream-to-triples(redirect="true")|
sort-triples(by="subject")|
collect-triples|
morph(FLUX_DIR + "output.xml")|
fix(FLUX_DIR + "output.fix")|
batch-log("merged ${totalRecords}", batchsize="100000")|
stream-to-triples|
template("${s}")|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 002@ not repeatable

if any_match("[email protected]", "^Tp.*$")
copy_field("[email protected]","ok")
end

# <!-- DBSM: -->
# <!-- (006U $0 “04p01*”) or (017A $a “yy”) -->
if any_match("006U.0","04p01.*")
add_field("@value","DBSM|ALL")
elsif any_equal("017A.a","yy")
add_field("@value","DBSM|ALL")

# <!-- DEA: -->
# <!-- (001@ $a 2””) or (209A $f “Exilarchiv” or 209A $f “HB/EB”) -->
elsif any_equal("[email protected]","2")
add_field("@value","DEA|ALL")
elsif any_equal("209A.f","HB/EB")
add_field("@value","DEA|ALL")

# <!-- DMA: -->
# <!-- (002@ $0 “G*” or 002@ $0 “M*”) or (006U $0 “10,P01*”) -->

elsif any_equal("[email protected]","^[GM].*")
add_field("@value","DMA|ALL")

elsif any_equal("006U.0","^10,P01.*")
add_field("@value","DMA|ALL")
else
add_field("@value","ALL")
end

# Test if type variable fits

if any_contain("@value","$[type]")
add_field("@value","$[type]")
else
remove_field("@value")
end

do list(path: "041A*|028A*|029B*|028C*|028Q*|028P*|028F*|028M*|028D*|028E*", "var":"$i")
trim("$i.9")
to_var("$i.9","ref")
if exists("$i.9")
copy_field("@value","{to:$[ref]}refed")
end
end

retain("{to*","ok")

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
unless exists("refed")
remove_field("ok","")
end

unless exists("ok")
remove_field("ok","")
end

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fileName|
open-file|
as-lines|
decode-pica|
morph(FLUX_DIR + "gnd-type.xml")|
fix(FLUX_DIR + "gnd-type.fix")|
stream-to-triples|
count-triples(countBy="object")|
template("${s}\t${o}")|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if any_match("[email protected]","...*")
replace_all("[email protected]","^(..).*","$1") #only keep the first two letters
retain("[email protected]") # only keep the relevent element
else
reject()
end
11 changes: 11 additions & 0 deletions metafacture-runner/src/main/dist/examples/count/subjects/10.pica

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
do list(path:"041A*","var":"$i")
copy_field("$i.9","relevantField.$append")
end

trim("relevantField.*")
uniq("relevantField")

retain("relevantField")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

default counts="myflux/counts.dat";
default counts=FLUX_DIR + "counts.dat";
default catalogue = FLUX_DIR + "10.pica";

//count references
Expand All @@ -10,10 +10,9 @@ open-file|
as-lines|
catch-object-exception|
decode-pica|
morph(FLUX_DIR + "references.xml")|
fix(FLUX_DIR + "references.fix")|
stream-to-triples|
count-triples(countBy="object")|

write("subjects.dat");
write(counts);


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if any_match("[email protected]","^Tp.*")
if any_match("041R.a",".*[Aa][Rr][Zz][Tt].*")
nothing()
else
reject()
end
else
reject()
end
11 changes: 11 additions & 0 deletions metafacture-runner/src/main/dist/examples/filter/fix/filter.flux
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// opens file 'fileName', interprets the content as pica and filters the results

default fileName = FLUX_DIR + "gnd-sample.pica";

fileName|
open-file|
as-lines|
decode-pica|
fix(FLUX_DIR + "filter.fix")| // Fix does not use the filter function but has its own filter mechanism within fix.
encode-formeta(style="verbose")|
write("stdout");
Loading
Loading