for (int i = 0; i <= data.numInstances - 1; i++) { Instance instance = data.getInstance(i); System.out.println(instance.stringValue(0)); //get Attribute 0 as String }
/** * Gets the next String from a Weka Instance * * @return the String value */ public String getNextWekaString() { Instance inst = this.iterator.next(); return inst.stringValue(this.index); }
private boolean isLabelSet(Instance instance, String labelName, Map<String, Attribute> attributesIndex) { if (instance.stringValue(attributesIndex.get(labelName)).equals("1")) return true; else return false; }
/** (3,1,2) -> "3+1+2" */ public static String encodeValue(Instance x, int indices[]) { String v = ""; for(int j = 0; j < indices.length; j++) { v+=x.stringValue(indices[j])+"+"; } v = v.substring(0,v.length()-1); return v; }
/** (3,1,2) -> "3+1+2" */ public static String encodeValue(Instance x, int indices[]) { String v = ""; for(int j = 0; j < indices.length; j++) { v+=x.stringValue(indices[j])+"+"; } v = v.substring(0,v.length()-1); return v; }
@Override public double distance(final Instance first, final Instance second, final double cutOffValue, final PerformanceStats stats) { final String[] fqCalls1 = first.stringValue(1).split(" "); final String[] fqCalls2 = second.stringValue(1).split(" "); final double seqDist = getSeqDistance(fqCalls1, fqCalls2); if (stats != null) stats.incrCoordCount(); return seqDist; }
@Override public double distance(final Instance first, final Instance second, final double cutOffValue, final PerformanceStats stats) { final String[] fqCaller1 = first.stringValue(0).split("\\."); final String[] fqCaller2 = second.stringValue(0).split("\\."); final double methodDist = getNameDistance(fqCaller1[fqCaller1.length - 1], fqCaller2[fqCaller2.length - 1]); final double classDist = getNameDistance(fqCaller1[fqCaller1.length - 2], fqCaller2[fqCaller2.length - 2]); final String[] fqCalls1 = first.stringValue(1).split(" "); final String[] fqCalls2 = second.stringValue(1).split(" "); final double seqDist = getSeqDistance(new HashSet<>(Arrays.asList(fqCalls1)), new HashSet<>(Arrays.asList(fqCalls2))); if (stats != null) stats.incrCoordCount(); return (methodDist + classDist + seqDist) / 3.; }
private void copyStringAttVals(InstanceHolder holder) { for (String attName : m_stringAttIndexes.keySet()) { Attribute att = holder.m_instance.dataset().attribute(attName); String val = holder.m_instance.stringValue(att); if (holder.m_stringVals == null) { holder.m_stringVals = new HashMap<String, String>(); } holder.m_stringVals.put(attName, val); } }
private void copyStringAttVals(InstanceHolder holder) { for (String attName : m_stringAttIndexes.keySet()) { Attribute att = holder.m_instance.dataset().attribute(attName); String val = holder.m_instance.stringValue(att); if (holder.m_stringVals == null) { holder.m_stringVals = new HashMap<String, String>(); } holder.m_stringVals.put(attName, val); } }
private void copyStringAttVals(InstanceHolder holder) { for (String attName : m_stringAttIndexes.keySet()) { Attribute att = holder.m_instance.dataset().attribute(attName); String val = holder.m_instance.stringValue(att); if (holder.m_stringVals == null) { holder.m_stringVals = new HashMap<String, String>(); } holder.m_stringVals.put(attName, val); } }
private void copyStringAttVals(InstanceHolder holder) { for (String attName : m_stringAttIndexes.keySet()) { Attribute att = holder.m_instance.dataset().attribute(attName); String val = holder.m_instance.stringValue(att); if (holder.m_stringVals == null) { holder.m_stringVals = new HashMap<String, String>(); } holder.m_stringVals.put(attName, val); } }
@Override public LabeledSentenceProvider getSentenceProvider(Instances data) { List<File> files = new ArrayList<>(); List<String> labels = new ArrayList<>(); final int clsIdx = data.classIndex(); for (Instance inst : data) { labels.add(String.valueOf(inst.value(clsIdx))); final String path = inst.stringValue(1 - clsIdx); final File file = Paths.get(textsLocation.getAbsolutePath(), path).toFile(); files.add(file); } return new FileLabeledSentenceProvider(files, labels, data.numClasses()); }
@Override public LabeledSentenceProvider getSentenceProvider(Instances data) { List<File> files = new ArrayList<>(); List<String> labels = new ArrayList<>(); final int clsIdx = data.classIndex(); for (Instance inst : data) { labels.add(String.valueOf(inst.value(clsIdx))); final String path = inst.stringValue(1 - clsIdx); final File file = Paths.get(textsLocation.getAbsolutePath(), path).toFile(); files.add(file); } return new FileLabeledSentenceProvider(files, labels, data.numClasses()); }
@Override public String evaluate() { if (isMissing()) { missingAccessed = true; return ""; } return instance.stringValue(getIndex()); } }
@Override public String evaluate() { if (isMissing()) { missingAccessed = true; return ""; } return instance.stringValue(getIndex()); } }
/** * The constructor. */ public Bag(Instance bagInstance) { instances = bagInstance.relationalValue(1); positive = bagInstance.classValue() == 1.0; bagWeight = 1.0 / instances.numInstances(); bagWeightMultiplied = bagWeight; id = bagInstance.stringValue(0); }
/** Test the getLabelForPath method. */ @Test public void testGetLabelForPath() { for (Instance inst : this.metaData) { String path = Paths.get(this.basePath, inst.stringValue(0)).toString(); String label = inst.stringValue(1); Assert.assertEquals(label, this.gen.getLabelForPath(path).toString()); Assert.assertEquals(label, this.gen.getLabelForPath(new File(path).toURI()).toString()); } }
/** Test the getPathUris method. */ @Test public void testGetPathUris() { final Collection<URI> pathURIs = this.gen.getPathURIs(); Collection<URI> metaDataUris = new HashSet<>(); this.metaData.forEach( instance -> metaDataUris.add(Paths.get(this.basePath, instance.stringValue(0)).toUri())); Assert.assertTrue(metaDataUris.containsAll(pathURIs)); Assert.assertTrue(pathURIs.containsAll(metaDataUris)); }
@Override public Instance output() { Instance outInst = m_delegate.output(); if (m_hasStringAtts && outInst != null) { for (int i = 0; i < outInst.dataset().numAttributes(); i++) { if (outInst.dataset().attribute(i).isString() && !outInst.isMissing(i)) { String val = outInst.stringValue(i); outInst.attribute(i).setStringValue(val); outInst.setValue(i, 0); } } } return outInst; }
public void testTypical() { m_Filter = getFilter(); Instances result = useFilter(); assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(m_Instances.numInstances(), result.numInstances()); // shouldn't be any 'b' values in the header - they should now // be 'bob' Attribute first = result.attribute(1); Attribute second = result.attribute(4); assertEquals(first.value(2), "bob"); assertEquals(second.value(1), "bob"); // check an instance Instance inst = result.instance(1); assertEquals(inst.stringValue(1), "bob"); assertEquals(inst.stringValue(4), "bob"); }