/** * Gets a component associated with the given parameter name. First search the component in * property table, then try to get component by name from the manager, then creates component with * default properties. * * @param name the parameter name * @return the component associated with the name * @throws edu.cmu.sphinx.util.props.PropertyException if the component does not exist or is of * the wrong type. */ public Configurable getComponent(String name) throws PropertyException { S4PropWrapper s4PropWrapper = getProperty(name, S4Component.class); Configurable configurable = null; S4Component s4Component = (S4Component) s4PropWrapper.getAnnotation(); Class<? extends Configurable> expectedType = s4Component.type(); Object propVal = propValues.get(name); if (propVal != null && propVal instanceof Configurable) { return (Configurable) propVal; } if (propVal != null && propVal instanceof String) { PropertySheet ps = cm.getPropertySheet(flattenProp(name)); if (ps != null) configurable = ps.getOwner(); else throw new InternalConfigurationException( getInstanceName(), name, "component '" + flattenProp(name) + "' is missing"); } if (configurable != null && !expectedType.isInstance(configurable)) throw new InternalConfigurationException( getInstanceName(), name, "mismatch between annotation and component type"); if (configurable != null) { propValues.put(name, configurable); return configurable; } configurable = getComponentFromAnnotation(name, s4Component); propValues.put(name, configurable); return configurable; }
/* * (non-Javadoc) * * @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet) */ @Override public void newProperties(PropertySheet ps) throws PropertyException { super.newProperties(ps); maxPathsPerWord = ps.getInt(PROP_MAX_PATHS_PER_WORD); maxFiller = ps.getInt(PROP_MAX_FILLER_WORDS); }
@Override public void newProperties(PropertySheet ps) throws PropertyException { super.newProperties(ps); logger = ps.getLogger(); create( ps.getInt(PROP_BYTES_PER_READ), ps.getComponentList(AUDIO_FILE_LISTENERS, AudioFileProcessListener.class)); }
@Override public void newProperties(PropertySheet ps) throws PropertyException { super.newProperties(ps); startSpeechTime = ps.getInt(PROP_START_SPEECH); endSilenceTime = ps.getInt(PROP_END_SILENCE); speechLeader = ps.getInt(PROP_SPEECH_LEADER); }
/* * (non-Javadoc) * * @see * edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util * .props.PropertySheet) */ @Override public void newProperties(PropertySheet ps) throws PropertyException { super.newProperties(ps); loader = (Loader) ps.getComponent(PROP_LOADER); try { loader.load(); } catch (IOException e) { throw new PropertyException(e); } initDataProcessors(); }
public TableIntegerProperty(JTable myTable, PropertySheet currentPS, String propName) { super(propName, myTable, currentPS); this.s4Integer = (S4Integer) currentPS.getProperty(propName, S4Integer.class).getAnnotation(); doubleEditor = new IntegerEditor(s4Integer.range()[0], s4Integer.range()[1]); Object rawValue = propSheet.getInt(propName); if (rawValue != null) doubleEditor.ftf.setValue(rawValue); doubleEditor.ftf.invalidate(); // else // doubleEditor.ftf.setValue(null); }
public void newProperties(PropertySheet ps) throws PropertyException { if (allocated) { throw new RuntimeException("Can't change properties after allocation"); } logMath = (LogMath) ps.getComponent(PROP_LOG_MATH); languageModels = ps.getComponentList(PROP_LANGUAGE_MODELS, LanguageModel.class); numberOfLanguageModels = languageModels.size(); // read weights as a String List. List<String> items = ps.getStringList(PROP_LANGUAGE_MODEL_WEIGHTS); if (items.size() != numberOfLanguageModels) { throw new RuntimeException("Number of weights not equal to number of language models"); } // convert Strings to floats and assign weights. float[] floats = new float[items.size()]; weights = new float[floats.length]; float weightSum = 0; for (int i = 0; i < items.size(); i++) { try { floats[i] = Float.parseFloat(items.get(i)); weightSum += floats[i]; weights[i] = logMath.linearToLog(floats[i]); } catch (NumberFormatException e) { throw new PropertyException( InterpolatedLanguageModel.class.getName(), PROP_LANGUAGE_MODEL_WEIGHTS, "Float value expected from the property list. But found:" + items.get(i)); } } if (weightSum < 1.0 - EPSILON || weightSum > 1.0 + EPSILON) { throw new PropertyException( InterpolatedLanguageModel.class.getName(), PROP_LANGUAGE_MODEL_WEIGHTS, "Weights do not sum to 1.0"); } }
@Override protected PropertySheet clone() throws CloneNotSupportedException { PropertySheet ps = (PropertySheet) super.clone(); ps.registeredProperties = new HashMap<String, S4PropWrapper>(this.registeredProperties); ps.propValues = new HashMap<String, Object>(this.propValues); ps.rawProps = new HashMap<String, Object>(this.rawProps); // make deep copy of raw-lists for (String regProp : ps.getRegisteredProperties()) { if (getType(regProp) == PropertyType.COMPONENT_LIST) { ps.rawProps.put(regProp, ConfigurationManagerUtils.toStringList(rawProps.get(regProp))); ps.propValues.put(regProp, null); } } ps.cm = cm; ps.owner = null; ps.instanceName = this.instanceName; return ps; }
public void newProperties(PropertySheet ps) throws PropertyException { logMath = LogMath.getLogMath(); logger = ps.getLogger(); unitManager = (UnitManager) ps.getComponent(PROP_UNIT_MANAGER); hmmManager = new HMMManager(); contextIndependentUnits = new LinkedHashMap<String, Unit>(); phoneList = new LinkedHashMap<String, Integer>(); meanTransformationMatrixPool = createDummyMatrixPool("meanTransformationMatrix"); meanTransformationVectorPool = createDummyVectorPool("meanTransformationMatrix"); varianceTransformationMatrixPool = createDummyMatrixPool("varianceTransformationMatrix"); varianceTransformationVectorPool = createDummyVectorPool("varianceTransformationMatrix"); String modelName = ps.getString(MODEL_NAME); String location = ps.getString(LOCATION); String phone = ps.getString(PHONE_LIST); String dataDir = ps.getString(DATA_DIR); logger.info("Creating Sphinx3 acoustic model: " + modelName); logger.info(" Path : " + location); logger.info(" phonelist : " + phone); logger.info(" dataDir : " + dataDir); // load the HMM model file boolean useCDUnits = ps.getBoolean(PROP_USE_CD_UNITS); assert !useCDUnits; try { loadPhoneList( ps, useCDUnits, StreamFactory.getInputStream(location, phone), location + File.separator + phone); } catch (StreamCorruptedException sce) { printPhoneListHelp(); } catch (IOException e) { e.printStackTrace(); } }
@Override public void newProperties(PropertySheet ps) throws PropertyException { super.newProperties(ps); logMath = (LogMath) ps.getComponent(PROP_LOG_MATH); }
/* (non-Javadoc) * @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet) */ public void newProperties(PropertySheet ps) throws PropertyException { linguist = (Linguist) ps.getComponent(PROP_LINGUIST); }
/* * (non-Javadoc) * * @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet) */ @Override public void newProperties(PropertySheet ps) throws PropertyException { parent = (LanguageModel) ps.getComponent(PROP_PARENT); }
/** * Loads the phone list, which possibly contains the sizes (number of states) of models. * * @param ps * @param useCDUnits if true, uses context dependent units * @param inputStream the open input stream to use * @param path the path to a density file @throws FileNotFoundException if a file cannot be found * @throws IOException if an error occurs while loading the data */ private void loadPhoneList( PropertySheet ps, boolean useCDUnits, InputStream inputStream, String path) throws IOException { int numState = 0; // TODO: this should be flexible, but we're hardwiring for now int numStreams = 1; // Since we're initializing, we start simple. int numGaussiansPerState = 1; ExtendedStreamTokenizer est = new ExtendedStreamTokenizer(inputStream, '#', false); // Initialize the pools we'll need. meansPool = new Pool<float[]>("means"); variancePool = new Pool<float[]>("variances"); mixtureWeightsPool = new Pool<float[]>("mixtureweights"); matrixPool = new Pool<float[][]>("transitionmatrices"); senonePool = new Pool<Senone>("senones"); float distFloor = ps.getFloat(PROP_MC_FLOOR); float mixtureWeightFloor = ps.getFloat(PROP_MW_FLOOR); float transitionProbabilityFloor = 0; float varianceFloor = ps.getFloat(PROP_VARIANCE_FLOOR); logger.info("Loading phone list file from: "); logger.info(path); // At this point, we only accept version 0.1 String version = "0.1"; est.expectString("version"); est.expectString(version); est.expectString("same_sized_models"); boolean sameSizedModels = est.getString().equals("yes"); if (sameSizedModels) { est.expectString("n_state"); numState = est.getInt("numBase"); } // for this phone list version, let's assume left-to-right // models, with optional state skip. est.expectString("tmat_skip"); boolean tmatSkip = est.getString().equals("yes"); // Load the phones with sizes // stateIndex contains the absolute state index, that is, a // unique index in the senone pool. for (int stateIndex = 0, unitCount = 0; ; ) { String phone = est.getString(); if (est.isEOF()) { break; } int size = numState; if (!sameSizedModels) { size = est.getInt("ModelSize"); } phoneList.put(phone, size); logger.fine("Phone: " + phone + " size: " + size); int[] stid = new int[size]; String position = "-"; for (int j = 0; j < size; j++, stateIndex++) { stid[j] = stateIndex; } Unit unit = unitManager.getUnit(phone, phone.equals(SILENCE_CIPHONE)); contextIndependentUnits.put(unit.getName(), unit); if (logger.isLoggable(Level.FINE)) { logger.fine("Loaded " + unit + " with " + size + " states"); } // Means addModelToDensityPool(meansPool, stid, numStreams, numGaussiansPerState); // Variances addModelToDensityPool(variancePool, stid, numStreams, numGaussiansPerState); // Mixture weights addModelToMixtureWeightPool( mixtureWeightsPool, stid, numStreams, numGaussiansPerState, mixtureWeightFloor); // Transition matrix addModelToTransitionMatrixPool( matrixPool, unitCount, stid.length, transitionProbabilityFloor, tmatSkip); // After creating all pools, we create the senone pool. addModelToSenonePool(senonePool, stid, distFloor, varianceFloor); // With the senone pool in place, we go through all units, and // create the HMMs. // Create tmat float[][] transitionMatrix = matrixPool.get(unitCount); SenoneSequence ss = getSenoneSequence(stid); HMM hmm = new SenoneHMM(unit, ss, transitionMatrix, HMMPosition.lookup(position)); hmmManager.put(hmm); unitCount++; } // If we want to use this code to load sizes/create models for // CD units, we need to find another way of establishing the // number of CI models, instead of just reading until the end // of file. est.close(); }
@Override public void newProperties(PropertySheet ps) throws PropertyException { super.newProperties(ps); featureBlockSize = ps.getInt(PROP_FEATURE_BLOCK_SIZE); }
public ExecutableExecutor(PropertySheet executablePS) { assert ConfigurationManagerUtils.isImplementingInterface( executablePS.getConfigurableClass(), Executable.class); this.executablePS = executablePS; }