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.data.columnar; 018 019import com.oracle.labs.mlrg.olcut.config.Configurable; 020import com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance; 021import com.oracle.labs.mlrg.olcut.provenance.Provenancable; 022 023import java.util.Optional; 024 025/** 026 * Extracts a value from a field to be placed in an {@link org.tribuo.Example}'s metadata field. 027 * Principally used to pull out Strings and floats for example names and weights respectively. 028 */ 029public interface FieldExtractor<T> extends Configurable, Provenancable<ConfiguredObjectProvenance> { 030 031 /** 032 * Gets the metadata key name. This is the key into which this value will be written in an {@link org.tribuo.Example} 033 * if it is given to {@link RowProcessor}. 034 * @return The metadata key name. 035 */ 036 public String getMetadataName(); 037 038 /** 039 * Gets the class of the value produced by this extractor. 040 * @return The class of the value. 041 */ 042 public Class<T> getValueType(); 043 044 /** 045 * Returns Optional which is filled if extraction succeeded. 046 * @param row The raw row from which to extract a value 047 * @return A value. 048 */ 049 Optional<T> extract(ColumnarIterator.Row row); 050}