Create an instance of a resource using default parameter values. @see #createResource(String,FeatureMap)
(String resourceClassName)
| 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 |