Commit 95d0d7ab authored by R.W.Majeed's avatar R.W.Majeed
Browse files

Reworked transformations

parent ba809851
package de.sekmi.histream.ontology.skos;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Consumer;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ObservationFactory;
......@@ -15,42 +13,13 @@ public class RDFTransformation implements Transformation {
public RDFTransformation(ObservationFactory factory){
this.factory = factory;
}
@Override
public Optional<Observation> transform(Observation fact) {
if( wantRemoved(fact) ) return Optional.empty();
Observation n = factory.createObservation(fact.getPatientId(), fact.getConceptId(), fact.getStartTime());
modify(n);
return Optional.of(n);
}
@Override
public Function<Observation, Observation> modificationFunction() {
public Observation transform(Observation fact,
Consumer<Observation> generatedReceiver) {
// TODO Auto-generated method stub
return null;
}
@Override
public Predicate<Observation> allowedPredicate() {
return new Predicate<Observation>() {
@Override
public boolean test(Observation t) {
return !wantRemoved(t);
}
};
}
@Override
public boolean wantRemoved(Observation fact) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean modify(Observation fact) {
// TODO Auto-generated method stub
return false;
}
}
package de.sekmi.histream.io;
import java.util.function.Supplier;
import de.sekmi.histream.Observation;
/**
* Perform transformation of {@link Observation}s for a {@link Supplier}.
* During the transformation, observations can be inserted, removed or modified.
* <p>
* Transformations are performed only on demand if {@link #get()} is called,
* until the supplier returns null.
* @author Raphael
*
*/
public class PullTransformer implements Supplier<Observation>{
private Supplier<Observation> source;
public PullTransformer(Supplier<Observation> source){
this.source = source;
}
@Override
public Observation get() {
// TODO filter, buffer
return source.get();
}
}
package de.sekmi.histream.io;
import java.util.function.Consumer;
import de.sekmi.histream.Observation;
public class PushTransformer implements Consumer<Observation>{
private Consumer<Observation> target;
public PushTransformer(Consumer<Observation> target){
this.target = target;
}
@Override
public void accept(Observation t) {
// TODO transform, buffer
target.accept(t);
}
}
package de.sekmi.histream.io;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Consumer;
import de.sekmi.histream.Observation;
......@@ -17,46 +15,20 @@ public interface Transformation {
/**
* Transforms a single observation.
* The original observation is not changed.
* The original observation might be changed, removed (if null is returned) or added
* (passed to the generatedReceiver).
* @param fact observation to transform
* @return new transformed observation or empty opional if it should be removed
* @return new transformed observation or empty optional if it should be removed
*/
Optional<Observation> transform(Observation fact);
/**
* Returns whether this transformation wants the supplied observation to be removed.
* @param fact observation to check for removal
* @return true if the observation should be removed, false to keep the observation
*/
boolean wantRemoved(Observation fact);
/**
* Modifies the supplied observation to match the transformation rule.
* @param fact observation to modify (in place)
* @return whether the supplied observation was modified.
*/
boolean modify(Observation fact);
/**
* Returns a function which applies this transformations
* modifications to any observation. Observations will not
* be removed by the returned function.
*
* @return function which applies this transformation
*/
Function<Observation, Observation> modificationFunction();
/**
* Returns a predicate which indicates whether to allow the
* observation.
* <p>
* The predicate's {@link Predicate#test(Object)} function will
* true if the argument should be allowed or modified, and false
* if the argument should be removed.
* @return predicate indicating whether to allow or remove an observation
*/
Predicate<Observation> allowedPredicate();
Observation transform(Observation fact, Consumer<Observation> generatedReceiver);
public static final Transformation Identity = new Transformation(){
@Override
public Observation transform(Observation fact,
Consumer<Observation> generatedReceiver) {
return fact;
}
};
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment