MCPcopy Create free account
hub / github.com/GateNLP/gate-core / createResource

Method createResource

src/main/java/gate/Factory.java:71–119  ·  view source on GitHub ↗

Create an instance of a resource using default parameter values. @see #createResource(String,FeatureMap)

(String resourceClassName)

Source from the content-addressed store, hash-verified

69 * @see #createResource(String,FeatureMap)
70 */
71 public static Resource createResource(String resourceClassName)
72 throws ResourceInstantiationException {
73 // get the resource metadata
74 ResourceData resData = Gate.getCreoleRegister().get(resourceClassName);
75 if(resData == null) {
76 Set<Plugin> plugins = Gate.getPlugins(resourceClassName);
77
78 StringBuilder msg = new StringBuilder();
79 msg.append("Couldn't get resource data for ").append(resourceClassName)
80 .append(".\n\n");
81
82 if(plugins.isEmpty()) {
83 msg.append("You may need first to load the plugin that contains your resource.\n");
84 msg.append("For example, to create a gate.creole.tokeniser.DefaultTokeniser\n");
85 msg.append("you need first to load the ANNIE plugin.\n\n");
86 } else if(plugins.size() == 1) {
87 msg.append(resourceClassName).append(" can be found in the ")
88 .append(plugins.iterator().next().getName())
89 .append(" plugin\n\n");
90 } else {
91 msg.append(resourceClassName).append(
92 " can be found in the following plugins\n ");
93 for(Plugin dInfo : plugins) {
94 msg.append(dInfo.getName()).append(", ");
95 }
96
97 msg.setLength(msg.length() - 2);
98 msg.append("\n\n");
99 }
100
101 msg.append("Go to the menu File->Manage CREOLE plugins or use the method\n");
102 msg.append("\"registerPlugin\" on Gate.getCreoleRegister()");
103
104 throw new ResourceInstantiationException(msg.toString());
105 }
106
107 // get the parameter list and default values
108 ParameterList paramList = resData.getParameterList();
109 FeatureMap parameterValues = null;
110 try {
111 parameterValues = paramList.getInitimeDefaults();
112 } catch(ParameterException e) {
113 throw new ResourceInstantiationException(
114 "Couldn't get default parameters for " + resourceClassName + ": "
115 + e);
116 }
117
118 return createResource(resourceClassName, parameterValues);
119 } // createResource(resClassName)
120
121 /**
122 * Create an instance of a resource, and return it. Callers of this

Callers 15

testAnnicIndexingMethod · 0.95
setUpMethod · 0.95
testTypeIndexMethod · 0.95
testAddWithNodesMethod · 0.95
testAnnotationSetMethod · 0.95
testDocumentOrderMethod · 0.95
testExplicitMimeTypeMethod · 0.95
testInstanceListsMethod · 0.95
testLoadingMethod · 0.95
testFactoryMethod · 0.95

Calls 15

getCreoleRegisterMethod · 0.95
getPluginsMethod · 0.95
getParameterListMethod · 0.95
getInitimeDefaultsMethod · 0.95
getResourceClassMethod · 0.95
getNlMethod · 0.95
getLrMethod · 0.95
addInstantiationMethod · 0.95
newFeatureMapMethod · 0.95
getNameMethod · 0.95
genSymMethod · 0.95
prlnMethod · 0.95

Tested by 15

testAnnicIndexingMethod · 0.76
setUpMethod · 0.76
testTypeIndexMethod · 0.76
testAddWithNodesMethod · 0.76
testAnnotationSetMethod · 0.76
testDocumentOrderMethod · 0.76
testExplicitMimeTypeMethod · 0.76
testInstanceListsMethod · 0.76
testLoadingMethod · 0.76
testFactoryMethod · 0.76