Search in sources :

Example 1 with ProvenanceException

use of com.oracle.labs.mlrg.olcut.provenance.ProvenanceException in project tribuo by oracle.

the class SkeletalTrainerProvenance method extractProvenanceInfo.

protected static ExtractedInfo extractProvenanceInfo(Map<String, Provenance> map) {
    String className;
    String hostTypeStringName;
    Map<String, Provenance> configuredParameters = new HashMap<>(map);
    Map<String, PrimitiveProvenance<?>> instanceValues = new HashMap<>();
    if (configuredParameters.containsKey(ObjectProvenance.CLASS_NAME)) {
        className = configuredParameters.remove(ObjectProvenance.CLASS_NAME).toString();
    } else {
        throw new ProvenanceException("Failed to find class name when constructing SkeletalTrainerProvenance");
    }
    if (configuredParameters.containsKey(SkeletalConfiguredObjectProvenance.HOST_SHORT_NAME)) {
        hostTypeStringName = configuredParameters.remove(SkeletalConfiguredObjectProvenance.HOST_SHORT_NAME).toString();
    } else {
        throw new ProvenanceException("Failed to find host type short name when constructing SkeletalTrainerProvenance");
    }
    if (configuredParameters.containsKey(TrainerProvenance.TRAIN_INVOCATION_COUNT)) {
        Provenance tmpProv = configuredParameters.remove(TrainerProvenance.TRAIN_INVOCATION_COUNT);
        if (tmpProv instanceof IntProvenance) {
            instanceValues.put(TRAIN_INVOCATION_COUNT, (IntProvenance) tmpProv);
        } else {
            throw new ProvenanceException(TRAIN_INVOCATION_COUNT + " was not of type IntProvenance in class " + className);
        }
    } else {
        throw new ProvenanceException("Failed to find invocation count when constructing SkeletalTrainerProvenance");
    }
    if (configuredParameters.containsKey(TrainerProvenance.IS_SEQUENCE)) {
        Provenance tmpProv = configuredParameters.remove(TrainerProvenance.IS_SEQUENCE);
        if (tmpProv instanceof BooleanProvenance) {
            instanceValues.put(IS_SEQUENCE, (BooleanProvenance) tmpProv);
        } else {
            throw new ProvenanceException(IS_SEQUENCE + " was not of type BooleanProvenance in class " + className);
        }
    } else {
        throw new ProvenanceException("Failed to find is-sequence when constructing SkeletalTrainerProvenance");
    }
    if (configuredParameters.containsKey(TrainerProvenance.TRIBUO_VERSION_STRING)) {
        Provenance tmpProv = configuredParameters.remove(TrainerProvenance.TRIBUO_VERSION_STRING);
        if (tmpProv instanceof StringProvenance) {
            instanceValues.put(TRIBUO_VERSION_STRING, (StringProvenance) tmpProv);
        } else {
            throw new ProvenanceException(TRIBUO_VERSION_STRING + " was not of type StringProvenance in class " + className);
        }
    } else {
        throw new ProvenanceException("Failed to find Tribuo version when constructing SkeletalTrainerProvenance");
    }
    return new ExtractedInfo(className, hostTypeStringName, configuredParameters, instanceValues);
}
Also used : PrimitiveProvenance(com.oracle.labs.mlrg.olcut.provenance.PrimitiveProvenance) BooleanProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.BooleanProvenance) ObjectProvenance(com.oracle.labs.mlrg.olcut.provenance.ObjectProvenance) Provenance(com.oracle.labs.mlrg.olcut.provenance.Provenance) BooleanProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.BooleanProvenance) StringProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance) SkeletalConfiguredObjectProvenance(com.oracle.labs.mlrg.olcut.provenance.impl.SkeletalConfiguredObjectProvenance) PrimitiveProvenance(com.oracle.labs.mlrg.olcut.provenance.PrimitiveProvenance) IntProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.IntProvenance) ProvenanceException(com.oracle.labs.mlrg.olcut.provenance.ProvenanceException) HashMap(java.util.HashMap) IntProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.IntProvenance) StringProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance)

Aggregations

ObjectProvenance (com.oracle.labs.mlrg.olcut.provenance.ObjectProvenance)1 PrimitiveProvenance (com.oracle.labs.mlrg.olcut.provenance.PrimitiveProvenance)1 Provenance (com.oracle.labs.mlrg.olcut.provenance.Provenance)1 ProvenanceException (com.oracle.labs.mlrg.olcut.provenance.ProvenanceException)1 SkeletalConfiguredObjectProvenance (com.oracle.labs.mlrg.olcut.provenance.impl.SkeletalConfiguredObjectProvenance)1 BooleanProvenance (com.oracle.labs.mlrg.olcut.provenance.primitives.BooleanProvenance)1 IntProvenance (com.oracle.labs.mlrg.olcut.provenance.primitives.IntProvenance)1 StringProvenance (com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance)1 HashMap (java.util.HashMap)1