-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from vitrivr/primitive-extraction-support
Support for PrimitiveTypeProvider in AbstractFeatureModule
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
.../org/vitrivr/cineast/core/data/entities/SimplePrimitiveTypeProviderFeatureDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.vitrivr.cineast.core.data.entities; | ||
|
||
import org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider; | ||
|
||
public class SimplePrimitiveTypeProviderFeatureDescriptor { | ||
|
||
public static final String[] FIELDNAMES = {"id", "feature"}; | ||
|
||
/** | ||
* ID of the {@link MediaSegmentDescriptor} this {@link SimplePrimitiveTypeProviderFeatureDescriptor} belongs to. | ||
*/ | ||
public final String segmentId; | ||
|
||
/** | ||
* Text that is contained in this {@link SimplePrimitiveTypeProviderFeatureDescriptor}. | ||
*/ | ||
public final PrimitiveTypeProvider feature; | ||
|
||
public SimplePrimitiveTypeProviderFeatureDescriptor(String segmentId, PrimitiveTypeProvider feature) { | ||
this.segmentId = segmentId; | ||
this.feature = feature; | ||
} | ||
|
||
public String getSegmentId() { | ||
return this.segmentId; | ||
} | ||
|
||
public PrimitiveTypeProvider getFeature() { | ||
return this.feature; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../org/vitrivr/cineast/core/db/dao/writer/PrimitiveTypeProviderFeatureDescriptorWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.vitrivr.cineast.core.db.dao.writer; | ||
|
||
import org.vitrivr.cineast.core.data.entities.SimplePrimitiveTypeProviderFeatureDescriptor; | ||
import org.vitrivr.cineast.core.db.PersistencyWriter; | ||
import org.vitrivr.cineast.core.db.PersistentTuple; | ||
|
||
public class PrimitiveTypeProviderFeatureDescriptorWriter extends AbstractBatchedEntityWriter<SimplePrimitiveTypeProviderFeatureDescriptor> { | ||
|
||
private final String entityname; | ||
|
||
public PrimitiveTypeProviderFeatureDescriptorWriter(PersistencyWriter<?> writer, String entityname) { | ||
this(writer, entityname, 1); | ||
} | ||
|
||
public PrimitiveTypeProviderFeatureDescriptorWriter(PersistencyWriter<?> writer, String entityname, int batchsize) { | ||
super(writer, batchsize, false); | ||
this.entityname = entityname; | ||
this.init(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
this.writer.open(this.entityname); | ||
} | ||
|
||
@Override | ||
protected PersistentTuple generateTuple(SimplePrimitiveTypeProviderFeatureDescriptor entity) { | ||
return this.writer.generateTuple(entity.getSegmentId(), entity.getFeature()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...core/src/main/java/org/vitrivr/cineast/core/features/example/PrimitiveFeatureExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.vitrivr.cineast.core.features.example; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import org.apache.commons.lang3.RandomUtils; | ||
import org.vitrivr.cineast.core.config.ReadableQueryConfig; | ||
import org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider; | ||
import org.vitrivr.cineast.core.data.score.ScoreElement; | ||
import org.vitrivr.cineast.core.data.segments.SegmentContainer; | ||
import org.vitrivr.cineast.core.db.setup.AttributeDefinition; | ||
import org.vitrivr.cineast.core.db.setup.AttributeDefinition.AttributeType; | ||
import org.vitrivr.cineast.core.db.setup.EntityCreator; | ||
import org.vitrivr.cineast.core.features.abstracts.AbstractFeatureModule; | ||
|
||
/** | ||
* This class serves as an example of how to implement an {@link AbstractFeatureModule}, but having a {@link PrimitiveTypeProvider} as a feature output. | ||
* Since this is in the example package, you have to provide the FQN, i.e. org.vitrivr.cineast.core.features.example.PrimitiveFeatureExample in the config to use it. | ||
*/ | ||
public class PrimitiveFeatureExample extends AbstractFeatureModule { | ||
|
||
/** | ||
* Our table name | ||
*/ | ||
public static final String PRIMITIVE_FEATURE_EXAMPLE_TABLE_NAME = "features_primitiveexample"; | ||
|
||
/** | ||
* {@link AbstractFeatureModule#vectorLength} is only used in {@link AbstractFeatureModule#initalizePersistentLayer(Supplier)}, so since we overwrite that method, it does not matter what we specify. | ||
* {@link AbstractFeatureModule#maxDist} is used for the correspondence function which processes all scores generated by the {@link #getSimilar(SegmentContainer, ReadableQueryConfig)} method. | ||
*/ | ||
public PrimitiveFeatureExample() { | ||
super(PRIMITIVE_FEATURE_EXAMPLE_TABLE_NAME, 5, 1); | ||
} | ||
|
||
/** | ||
* Here, you can do whatever you want for a given shot. You can store multiple objects per shot. | ||
*/ | ||
@Override | ||
public void processSegment(SegmentContainer shot) { | ||
this.persist(shot.getId(), PrimitiveTypeProvider.fromObject(RandomUtils.nextFloat(0, 5))); | ||
} | ||
|
||
/** | ||
* This heavily depends on your feature. In general, you will want to perform some sort of retrieval using the {@link #selector} associated with this feature and then return {@link ScoreElement} which map the id of a multimediasegment or object to a score between 0 and {@link #maxDist} | ||
*/ | ||
@Override | ||
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) { | ||
// not supported by default. Implement your own using this.selector | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** | ||
* Here, we initialize the underlying database layer. This heavily depends on your feature. | ||
*/ | ||
@Override | ||
public void initalizePersistentLayer(Supplier<EntityCreator> supply) { | ||
supply.get().createFeatureEntity(PRIMITIVE_FEATURE_EXAMPLE_TABLE_NAME, true, new AttributeDefinition("feature", AttributeType.FLOAT)); | ||
} | ||
} |