public abstract class Factory extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Factory.DuplicationContext
Opaque memo object passed to
CustomDuplication.duplicate methods to encapsulate the state of
the current duplication run. |
Constructor and Description |
---|
Factory() |
Modifier and Type | Method and Description |
---|---|
static void |
addCreoleListener(CreoleListener l)
Add a listener
|
protected static void |
checkDuplicationContext(Factory.DuplicationContext ctx)
Throws an exception if the specified duplication context is null or
not active.
|
static DataStore |
createDataStore(String dataStoreClassName,
String storageUrl)
Create a new DataStore and open it.
|
static AnnotationSet |
createImmutableAnnotationSet(Document document,
Collection<Annotation> annotations)
Utility method to create an immutable annotation set.
|
static Resource |
createResource(String resourceClassName)
Create an instance of a resource using default parameter values.
|
static Resource |
createResource(String resourceClassName,
FeatureMap parameterValues)
Create an instance of a resource, and return it.
|
static Resource |
createResource(String resourceClassName,
FeatureMap parameterValues,
FeatureMap features)
Create an instance of a resource, and return it.
|
static Resource |
createResource(String resourceClassName,
FeatureMap parameterValues,
FeatureMap features,
String resourceName)
Create an instance of a resource, and return it.
|
static Resource |
defaultDuplicate(Resource res,
Factory.DuplicationContext ctx)
Implementation of the default duplication algorithm described in
the comment for
duplicate(Resource) . |
static void |
deleteResource(Resource resource)
Delete an instance of a resource.
|
static FeatureMap |
duplicate(FeatureMap fm,
Factory.DuplicationContext ctx)
Construct a feature map that is a copy of the one provided except
that any
Resource values in the map are replaced by their
duplicates. |
static Resource |
duplicate(Resource res)
Create a duplicate of the given resource.
|
static Resource |
duplicate(Resource res,
Factory.DuplicationContext ctx)
Create a duplicate of the given resource, using the provided
context.
|
protected static DataStore |
instantiateDataStore(String dataStoreClassName,
String storageUrl)
Instantiate a DataStore (not open or created).
|
static Corpus |
newCorpus(String name)
Create a new transient Corpus.
|
static Document |
newDocument(String content)
Create a new transient textual Document from a string.
|
static Document |
newDocument(URL sourceUrl)
Create a new transient Document from a URL.
|
static Document |
newDocument(URL sourceUrl,
String encoding)
Create a new transient Document from a URL and an encoding.
|
static FeatureMap |
newFeatureMap()
Create a new FeatureMap.
|
static DataStore |
openDataStore(String dataStoreClassName,
String storageUrl)
Open an existing DataStore.
|
public static Resource createResource(String resourceClassName) throws ResourceInstantiationException
ResourceInstantiationException
createResource(String,FeatureMap)
public static Resource createResource(String resourceClassName, FeatureMap parameterValues) throws ResourceInstantiationException
resourceClassName
- the name of the class implementing the
resource.parameterValues
- the feature map containing intialisation
time parameterValues for the resource.ResourceInstantiationException
public static Resource createResource(String resourceClassName, FeatureMap parameterValues, FeatureMap features) throws ResourceInstantiationException
resourceClassName
- the name of the class implementing the
resource.parameterValues
- the feature map containing intialisation
time parameterValues for the resource.features
- the features for the new resourceResourceInstantiationException
public static Resource createResource(String resourceClassName, FeatureMap parameterValues, FeatureMap features, String resourceName) throws ResourceInstantiationException
resourceClassName
- the name of the class implementing the
resource.parameterValues
- the feature map containing intialisation
time parameterValues for the resource.features
- the features for the new resource or null to not
assign any (new) features.resourceName
- the name to be given to the resource or null to
assign a default name.ResourceInstantiationException
public static void deleteResource(Resource resource)
resource
- the resource to be deleted.public static Corpus newCorpus(String name) throws ResourceInstantiationException
ResourceInstantiationException
public static Document newDocument(URL sourceUrl) throws ResourceInstantiationException
ResourceInstantiationException
public static Document newDocument(URL sourceUrl, String encoding) throws ResourceInstantiationException
ResourceInstantiationException
public static Document newDocument(String content) throws ResourceInstantiationException
ResourceInstantiationException
public static AnnotationSet createImmutableAnnotationSet(Document document, Collection<Annotation> annotations)
null
, the newly created set will
be empty.document
- the document this set belongs to.annotations
- the set of annotations that should be contained
in the returned AnnotationSet
.AnnotationSet
that throws exceptions on all
attempts to modify it.public static Resource duplicate(Resource res) throws ResourceInstantiationException
Create a duplicate of the given resource. A duplicate is a an independent copy of the resource that has the same name and the same behaviour. It does not necessarily have the same concrete class as the original, but if the original resource implements any of the following interfaces then the duplicate can be assumed to implement the same ones:
ProcessingResource
LanguageAnalyser
Controller
CorpusController
ConditionalController
Gazetteer
LanguageResource
Ontology
Document
Corpus
The default duplication algorithm simply calls
createResource
with the type and name of the original resource,
and with parameters and features which are copies of those from the
original resource, but any Resource values in the maps will
themselves be duplicated. A context is passed around all the
duplicate calls that stem from the same call to this method so that
if the same resource is referred to in different places, the same
duplicate can be used in the corresponding places in the duplicated
object graph.
This default behaviour is sufficient for most resource types (and
is roughly the equivalent of saving the resource's state using the
persistence manager and then reloading it), but individual resource
classes can override it by implementing the
CustomDuplication
interface. This may be necessary for
semantic reasons (e.g. controllers need to recursively duplicate
the PRs they contain), or desirable for performance or memory
consumption reasons (e.g. the behaviour of a DefaultGazetteer can
be duplicated by a SharedDefaultGazetteer that shares the internal
data structures).
res
- the resource to duplicateResourceInstantiationException
- if an exception occurs while
constructing the duplicate.public static Resource duplicate(Resource res, Factory.DuplicationContext ctx) throws ResourceInstantiationException
CustomDuplication
interface when they need to
duplicate their child resources. Calls made to this method outside
the scope of such a CustomDuplication.duplicate
call will fail with a runtime
exception.res
- the resource to duplicatectx
- the current context as passed to the
CustomDuplication.duplicate(gate.Factory.DuplicationContext)
method.ResourceInstantiationException
- if an error occurs while
constructing the duplicate.duplicate(Resource)
public static Resource defaultDuplicate(Resource res, Factory.DuplicationContext ctx) throws ResourceInstantiationException
duplicate(Resource)
. This method is public
for the benefit of resources that implement
CustomDuplication
but only need to do some post-processing
after the default duplication algorithm; they can call this method
to obtain an initial duplicate and then post-process it before
returning. If they need to duplicate child resources they should
call duplicate(Resource, DuplicationContext)
in the normal
way. Calls to this method made outside the context of a
CustomDuplication.duplicate
call will fail with a runtime exception.res
- the resource to duplicatectx
- the current contextres
implements CustomDuplication
its own duplicate
method will not be called.ResourceInstantiationException
- if an error occurs while
duplicating the given resource.public static FeatureMap duplicate(FeatureMap fm, Factory.DuplicationContext ctx) throws ResourceInstantiationException
Resource
values in the map are replaced by their
duplicates. This method is public for the benefit of resources that
implement CustomDuplication
and will fail if called outside
of a CustomDuplication.duplicate
implementation.fm
- the feature map to duplicatectx
- the current contextResourceInstantiationException
- if an error occurs while
duplicating any Resource in the feature map.protected static void checkDuplicationContext(Factory.DuplicationContext ctx)
duplicate(Resource)
call.ctx
- the context to check.NullPointerException
- if the provided context is null.IllegalStateException
- if the provided context is not
active.public static FeatureMap newFeatureMap()
public static DataStore openDataStore(String dataStoreClassName, String storageUrl) throws PersistenceException
PersistenceException
public static DataStore createDataStore(String dataStoreClassName, String storageUrl) throws PersistenceException, UnsupportedOperationException
protected static DataStore instantiateDataStore(String dataStoreClassName, String storageUrl) throws PersistenceException
PersistenceException
public static void addCreoleListener(CreoleListener l)
Copyright © 2024 GATE. All rights reserved.