/** * FIXME: to be dropped. * * <p>Read out a view configuration setting. * * <p>Compare to client-side counterpart: function get_view_config() in webclient.js * * @param configTypeUri The type URI of the configuration topic, e.g. "dm4.webclient.view_config" * @param settingUri The setting URI, e.g. "dm4.webclient.icon" * @return The setting value, or <code>null</code> if there is no such setting */ public Object getSetting(String configTypeUri, String settingUri) { TopicModel configTopic = getConfigTopic(configTypeUri); if (configTopic == null) { return null; } CompositeValue comp = configTopic.getCompositeValue(); return comp.has(settingUri) ? comp.get(settingUri) : null; }
public void toJSON(JSONObject configurable) { try { List viewConfigTopics = new ArrayList(); for (TopicModel configTopic : getConfigTopics()) { viewConfigTopics.add(configTopic.toJSON()); } configurable.put("view_config_topics", viewConfigTopics); } catch (Exception e) { throw new RuntimeException("Serialization failed (" + this + ")", e); } }
public boolean addSetting(String configTypeUri, String settingUri, Object value) { boolean configTopicCreated = false; // create config topic if not exists TopicModel configTopic = getConfigTopic(configTypeUri); if (configTopic == null) { configTopic = new TopicModel(configTypeUri); addConfigTopic(configTopic); configTopicCreated = true; } // make setting configTopic.getCompositeValue().put(settingUri, value); // return configTopicCreated; }
@Test public void nullTest() throws Exception { TextCorpus corpus = new TextCorpus(); corpus.add("foo bar baz classify me test"); corpus.add("foo baz baz2 classify me test"); corpus.add("somefoo baz baz2 classify me test waz maz zaz"); TopicModel model = new TopicModel("foo"); model.update(corpus); for (String doc : corpus.getDocs()) { // int topic = model.getMaxLikelihoodTopic(doc); System.out.println((model.getMaxLikelihoodTopic(doc)).toString()); } }
@Override public CompositeValueModel clone() { CompositeValueModel clone = new CompositeValueModel(); for (String childTypeUri : this) { Object value = get(childTypeUri); if (value instanceof TopicModel) { TopicModel model = (TopicModel) value; clone.put(childTypeUri, model.clone()); } else if (value instanceof List) { for (TopicModel model : (List<TopicModel>) value) { clone.add(childTypeUri, model.clone()); } } else { throw new RuntimeException("Unexpected value in a CompositeValueModel: " + value); } } return clone; }
public void updateConfigTopic(TopicModel configTopic) { String configTypeUri = configTopic.getTypeUri(); // error check TopicModel existing = getConfigTopic(configTypeUri); if (existing == null) { throw new RuntimeException( "There is no configuration topic of type \"" + configTypeUri + "\""); } // viewConfig.put(configTypeUri, configTopic); }
/** Print the model. */ public void printModel(String outputDirectory) { try { String domain = model.param.domain; printModelParameters(model.param, outputDirectory + domain + modelParamSuffix); printTopicWordAssignment(model.z, model.corpus, outputDirectory + domain + tassignSuffix); printDocumentTopicDistribution( model.getDocumentTopicDistrbution(), outputDirectory + domain + documentTopicDistSuff); printTopicWordDistribution( model.getTopicWordDistribution(), outputDirectory + domain + topicWordDistSuff); ArrayList<ArrayList<ItemWithValue>> topWordsUnderTopics = model.getTopWordStrsWithProbabilitiesUnderTopics(model.param.twords); printTopWordsUnderTopics(topWordsUnderTopics, outputDirectory + domain + twordsSuffix); printDocs(model.corpus.docs, outputDirectory + domain + docsSuffix); printVocabulary(model.corpus.vocab, outputDirectory + domain + vocabSuffix); // For knowledge-based topic models only. model.printKnowledge(outputDirectory + domain + knowledgeSuffix); } catch (Exception ex) { System.out.println("Error while printing the topic model: " + ex.getMessage()); ex.printStackTrace(); } }
private void initializeModel() { TopicModel topicModel = new TopicModel( numTopics, numTerms, eta, alpha, RandomUtils.getRandom(), terms, numUpdatingThreads, initialModelCorpusFraction == 0 ? 1 : initialModelCorpusFraction * totalCorpusWeight); topicModel.setConf(getConf()); TopicModel updatedModel = initialModelCorpusFraction == 0 ? new TopicModel(numTopics, numTerms, eta, alpha, null, terms, numUpdatingThreads, 1) : topicModel; updatedModel.setConf(getConf()); docTopicCounts = new DenseMatrix(numDocuments, numTopics); docTopicCounts.assign(1.0 / numTopics); modelTrainer = new ModelTrainer(topicModel, updatedModel, numTrainingThreads, numTopics, numTerms); }
/** * Convenience accessor for the *composite* value of a single-valued child. Returns a default * value if the child doesn't exist. */ public CompositeValueModel getCompositeValueModel( String childTypeUri, CompositeValueModel defaultValue) { TopicModel topic = getTopic(childTypeUri, null); return topic != null ? topic.getCompositeValueModel() : defaultValue; }
/** * Convenience accessor for the *simple* value of a single-valued child. Returns a default value * if the child doesn't exist. */ public Object getObject(String childTypeUri, Object defaultValue) { TopicModel topic = getTopic(childTypeUri, null); return topic != null ? topic.getSimpleValue().value() : defaultValue; }
/** * Convenience accessor for the *simple* value of a single-valued child. Returns a default value * if the child doesn't exist. */ public boolean getBoolean(String childTypeUri, boolean defaultValue) { TopicModel topic = getTopic(childTypeUri, null); return topic != null ? topic.getSimpleValue().booleanValue() : defaultValue; }
/** * Convenience accessor for the *simple* value of a single-valued child. Returns a default value * if the child doesn't exist. */ public double getDouble(String childTypeUri, double defaultValue) { TopicModel topic = getTopic(childTypeUri, null); return topic != null ? topic.getSimpleValue().doubleValue() : defaultValue; }
/** * Convenience accessor for the *simple* value of a single-valued child. Returns a default value * if the child doesn't exist. */ public long getLong(String childTypeUri, long defaultValue) { TopicModel topic = getTopic(childTypeUri, null); return topic != null ? topic.getSimpleValue().longValue() : defaultValue; }
/** * Convenience accessor for the *simple* value of a single-valued child. Returns a default value * if the child doesn't exist. */ public int getInt(String childTypeUri, int defaultValue) { TopicModel topic = getTopic(childTypeUri, null); return topic != null ? topic.getSimpleValue().intValue() : defaultValue; }