001/*
002 * Copyright (c) 2015-2020, Oracle and/or its affiliates. All rights reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.tribuo.provenance.impl;
018
019import com.oracle.labs.mlrg.olcut.provenance.Provenance;
020import org.tribuo.Output;
021import org.tribuo.Trainer;
022import org.tribuo.provenance.SkeletalTrainerProvenance;
023import org.tribuo.provenance.TrainerProvenance;
024import org.tribuo.sequence.SequenceTrainer;
025
026import java.util.Map;
027
028/**
029 * An implementation of {@link TrainerProvenance} that delegates everything to
030 * {@link SkeletalTrainerProvenance}. Used for trainers which don't
031 * require additional information stored beyond their configurable parameters
032 * and the standard trainer instance parameters.
033 */
034public final class TrainerProvenanceImpl extends SkeletalTrainerProvenance {
035    private static final long serialVersionUID = 1L;
036
037    /**
038     * Construct a TrainerProvenance by reading all the configurable parameters
039     * along with the train call count.
040     * @param host The trainer to inspect.
041     * @param <T> The type of the {@link Output}.
042     */
043    public <T extends Output<T>> TrainerProvenanceImpl(Trainer<T> host) {
044        super(host);
045    }
046
047    /**
048     * Construct a TrainerProvenance by reading all the configurable parameters
049     * along with the train call count.
050     * @param host The sequence trainer to inspect.
051     * @param <T> The type of the {@link Output}.
052     */
053    public <T extends Output<T>> TrainerProvenanceImpl(SequenceTrainer<T> host) {
054        super(host);
055    }
056
057    /**
058     * Construct a TrainerProvenance by extracting the necessary fields from the supplied
059     * map.
060     * @param map The serialised form of this provenance.
061     */
062    public TrainerProvenanceImpl(Map<String, Provenance> map) {
063        super(extractProvenanceInfo(map));
064    }
065}