code
stringlengths
146
466k
prompt
stringlengths
54
1.5k
Of course, here is the Java code you requested: ```java public String nextString() { char[] buffer = new char[nextInt()]; for (int i = 0; i < buffer.length; ++i) { buffer[i] = nextChar(); } return new String(buffer); } ``` Hope this helps!
Create a Java method that does the following: "Get the next string in the sequence.".
Of course, here is the Java code you requested: ```java public static IndexMaps createIndices(String conllPath, boolean labeled, boolean lowercased, String clusterFile) throws IOException { HashMap<String, Integer> wordMap = new HashMap<String, Integer>(); HashMap<Integer, Integer> labels = new Has...
Create a Java method that does the following: "Create the IndexMaps object from the specified conllPath.".
Of course, here is the Java code you requested: ```java public void connect(int from, int to, double weight) { edgesTo[to].add(new EdgeFrom(from, weight, vertexes[from].word + '@' + vertexes[to].word)); } ``` Hope this helps!
Create a Java method that does the following: "Connect two words.".
Of course, here is the Java code you requested: ```java public List<Vertex> parsePath(int[] path) { List<Vertex> vertexList = new LinkedList<Vertex>(); for (int i : path) { vertexList.add(vertexes[i]); } return vertexList; } ``` Hope this helps!
Create a Java method that does the following: "Parse a path of a CRA to a CRA list of Vertices.".
Of course, here is the Java code you requested: ```java public void learn(List<Sentence> sentenceList) { List<List<IWord>> s = new ArrayList<List<IWord>>(sentenceList.size()); for (Sentence sentence : sentenceList) { s.add(sentence.wordList); } compute(s); } ...
Create a Java method that does the following: "This method is called to learn a list of words.".
Of course, here is the Java code you requested: ```java public void train(String corpus) { CorpusLoader.walk(corpus, new CorpusLoader.Handler() { @Override public void handle(Document document) { List<List<Word>> simpleSentenceList = document.getS...
Create a Java method that does the following: "Train the CRA - Trees".
Of course, here is the Java code you requested: ```java void build() { _ranks = new int[_units.size()]; _numOnes = 0; for (int i = 0; i < _units.size(); ++i) { _ranks[i] = _numOnes; _numOnes += popCount(_units.get(i)); } } ``` Hope this helps!
Create a Java method that does the following: "Build the base class.".
Of course, here is the Java code you requested: ```java private static int popCount(int unit) { unit = ((unit & 0xAAAAAAAA) >>> 1) + (unit & 0x55555555); unit = ((unit & 0xCCCCCCCC) >>> 2) + (unit & 0x33333333); unit = ((unit >>> 4) + unit) & 0x0F0F0F0F; unit += unit >>> 8; ...
Create a Java method that does the following: "popCount returns the count of the unit in the sequence of bytes.".
Of course, here is the Java code you requested: ```java public Sentence makeSentence(String[] words, String[] posTags, boolean rootFirst, boolean lowerCased) { ArrayList<Integer> tokens = new ArrayList<Integer>(); ArrayList<Integer> tags = new ArrayList<Integer>(); ArrayList<Integer> bc4 = ...
Create a Java method that does the following: "Creates a Sentence object from the given words and posTags.".
Of course, here is the Java code you requested: ```java public int[] clusterId(String word) { int[] ids = new int[3]; ids[0] = -100; ids[1] = -100; ids[2] = -100; if (brownFullClusters.containsKey(word)) ids[0] = brownFullClusters.get(word); if (ids[0] >...
Create a Java method that does the following: "Get the clusterId of a single word.".
Of course, here is the Java code you requested: ```java public List<String> segment(String sentence) { return segment(sentence, CharTable.convert(sentence)); } ``` Hope this helps!
Create a Java method that does the following: "segment a sentence into a sequence of tokens.".
Of course, here is the Java code you requested: ```java public List<String> segment(final String sentence, final String normalized) { final List<String> wordList = new LinkedList<String>(); segment(sentence, normalized, wordList); return wordList; } ``` Hope this helps!
Create a Java method that does the following: "segment a sentence into a list of words.".
Of course, here is the Java code you requested: ```java protected boolean acceptCustomWord(int begin, int end, CoreDictionary.Attribute value) { return config.forceCustomDictionary || (end - begin >= 4 && !value.hasNatureStartsWith("nr") && !value.hasNatureStartsWith("ns") && !value.hasNatureStartsWith("nt...
Create a Java method that does the following: "Accept a custom word.".
Of course, here is the Java code you requested: ```java private void pushPiece(String sentence, String normalized, int start, int end, byte preType, List<String> wordList) { if (preType == CharType.CT_CHINESE) { segmenter.segment(sentence.substring(start, end), normalized.substring(star...
Create a Java method that does the following: "Push a piece of text to the word list.".
Of course, here is the Java code you requested: ```java protected void segmentAfterRule(String sentence, String normalized, List<String> wordList) { if (!enableRuleBasedSegment) { segmenter.segment(sentence, normalized, wordList); return; } int start = 0; ...
Create a Java method that does the following: "segmentAfterRule Method.".
Of course, here is the Java code you requested: ```java private List<CoreDictionary.Attribute> segmentWithAttribute(String original, String normalized, List<String> wordList) { List<CoreDictionary.Attribute> attributeList; if (config.useCustomDictionary) { if (config.forceCustom...
Create a Java method that does the following: "segmentWithAttribute This method is used to segment the wordList with the attribute.".
Of course, here is the Java code you requested: ```java protected static List<CoreDictionary.Attribute> combineWithCustomDictionary(List<String> vertexList) { String[] wordNet = new String[vertexList.size()]; vertexList.toArray(wordNet); CoreDictionary.Attribute[] attributeArray = new CoreD...
Create a Java method that does the following: "Combine with custom dictionary.".
Of course, here is the Java code you requested: ```java private static void combineWords(String[] wordNet, int start, int end, CoreDictionary.Attribute[] attributeArray, CoreDictionary.Attribute value) { if (start + 1 != end) // 小优化,如果只有一个词,那就不需要合并,直接应用新属性 { StringBuilder sbTerm = new...
Create a Java method that does the following: "Combine words.".
Of course, here is the Java code you requested: ```java public void save(DataOutputStream out) throws Exception { out.writeInt(size); for (int i = 0; i < size; i++) { out.writeInt(base[i]); out.writeInt(check[i]); out.writeInt(fail[i]); int ou...
Create a Java method that does the following: "Save the result to the specified output stream.".
Of course, here is the Java code you requested: ```java public void save(ObjectOutputStream out) throws IOException { out.writeObject(base); out.writeObject(check); out.writeObject(fail); out.writeObject(output); out.writeObject(l); } ``` Hope this helps!
Create a Java method that does the following: "Saves the result of this exception to the specified output stream.".
Of course, here is the Java code you requested: ```java public void load(ObjectInputStream in, V[] value) throws IOException, ClassNotFoundException { base = (int[]) in.readObject(); check = (int[]) in.readObject(); fail = (int[]) in.readObject(); output = (int[][]) in.readObject();...
Create a Java method that does the following: "Load the CID from an input stream.".
Of course, here is the Java code you requested: ```java public boolean load(ByteArray byteArray, V[] value) { if (byteArray == null) return false; size = byteArray.nextInt(); base = new int[size + 65535]; // 多留一些,防止越界 check = new int[size + 65535]; fail = new int[size + 65...
Create a Java method that does the following: "Load a single class from a ByteArray.".
Of course, here is the Java code you requested: ```java private int getState(int currentState, char character) { int newCurrentState = transitionWithRoot(currentState, character); // 先按success跳转 while (newCurrentState == -1) // 跳转失败的话,按failure跳转 { currentState = fail[currentSta...
Create a Java method that does the following: "getState - get the new state".
Of course, here is the Java code you requested: ```java @SuppressWarnings("unchecked") public Collection<Emit> parseText(String text) { checkForConstructedFailureStates(); int position = 0; State currentState = this.rootState; List<Emit> collectedEmits = new ArrayList<Emit>(); ...
Create a Java method that does the following: "Parses the text into a Collection of Emit objects.".
Of course, here is the Java code you requested: ```java private static void storeEmits(int position, State currentState, List<Emit> collectedEmits) { Collection<String> emits = currentState.emit(); if (emits != null && !emits.isEmpty()) { for (String emit : emits) { ...
Create a Java method that does the following: "Stores the emits of the sequence of tokens".
Of course, here is the Java code you requested: ```java static boolean load(Map<String, String> storage, boolean reverse, String... pathArray) { StringDictionary dictionary = new StringDictionary("="); for (String path : pathArray) { if (!dictionary.load(path)) return false; ...
Create a Java method that does the following: "Load a set of CRASS attributes from a file or directory.".
Of course, here is the Java code you requested: ```java static boolean load(String path, AhoCorasickDoubleArrayTrie<String> trie, boolean reverse) { String datPath = path; if (reverse) { datPath += Predefine.REVERSE_EXT; } if (loadDat(datPath, trie)) return true;...
Create a Java method that does the following: "Load a single AhoCorasickDoubleArrayTrie.".
Of course, here is the Java code you requested: ```java private static Double max(Map<String, Double> map) { Double theMax = 0.0; for (Double v : map.values()) { theMax = Math.max(theMax, v); } return theMax; } ``` Hope this helps!
Create a Java method that does the following: "Get the max value of a map of CRAs.".
Of course, here is the Java code you requested: ```java protected void addToOverlaps(Intervalable interval, List<Intervalable> overlaps, List<Intervalable> newOverlaps) { for (Intervalable currentInterval : newOverlaps) { if (!currentInterval.equals(interval)) { ...
Create a Java method that does the following: "Add to the list of overlapping intervals.".
Of course, here is the Java code you requested: ```java public boolean learn(Instance instance) { if (instance == null) return false; model.update(instance); return true; } ``` Hope this helps!
Create a Java method that does the following: "Learn a single instance of a CID .".
Of course, here is the Java code you requested: ```java public BaseNode<V> transition(char path) { BaseNode<V> cur = this; cur = cur.getChild(path); if (cur == null || cur.status == Status.UNDEFINED_0) return null; return cur; } ``` Hope this helps!
Create a Java method that does the following: "Transition to a child of this node.".
Of course, here is the Java code you requested: ```java public static final Nature fromString(String name) { Integer id = idMap.get(name); if (id == null) return null; return values[id]; } ``` Hope this helps!
Create a Java method that does the following: "Get a Nature object from a string.".
Of course, here is the Java code you requested: ```java public static final Nature create(String name) { Nature nature = fromString(name); if (nature == null) return new Nature(name); return nature; } ``` Hope this helps!
Create a Java method that does the following: "Create a Nature object from a string.".
Of course, here is the Java code you requested: ```java @Override public int[] toIdList(int codePoint) { int count; if (codePoint < 0x80) count = 1; else if (codePoint < 0x800) count = 2; else if (codePoint < 0x10000) count = 3; else i...
Create a Java method that does the following: "Override toIdList to return an array of int for a single code point.".
Of course, here is the Java code you requested: ```java public static TriaFrequency create(String first, char delimiter, String second, String third) { TriaFrequency triaFrequency = new TriaFrequency(first + delimiter + second + Occurrence.RIGHT + third); triaFrequency.first = first; triaFr...
Create a Java method that does the following: "Create a TriaFrequency object from the given strings.".
Of course, here is the Java code you requested: ```java public void train(String templFile, String trainFile, String modelFile, int maxitr, int freq, double eta, double C, int threadNum, int shrinkingSize, Encoder.Algorithm algorithm) throws IOException { Encoder...
Create a Java method that does the following: "Train a single tag set from a templ file and a model file.".
Of course, here is the Java code you requested: ```java public String getTemplate() { String template = getDefaultFeatureTemplate(); if (model != null && model.getFeatureTemplateArray() != null) { StringBuilder sbTemplate = new StringBuilder(); for (FeatureTemplate f...
Create a Java method that does the following: "Get the template of the coding.".
Of course, here is the Java code you requested: ```java public static Word create(String param) { if (param == null) return null; int cutIndex = param.lastIndexOf('/'); if (cutIndex <= 0 || cutIndex == param.length() - 1) { logger.warning("使用 " + param + "创建单个单词失败"); ...
Create a Java method that does the following: "create a CRS word from a URL".
Of course, here is the Java code you requested: ```java public CoNLLWord[] getWordArrayWithRoot() { CoNLLWord[] wordArray = new CoNLLWord[word.length + 1]; wordArray[0] = CoNLLWord.ROOT; System.arraycopy(word, 0, wordArray, 1, word.length); return wordArray; } ``` Hope this he...
Create a Java method that does the following: "Returns the word array with the root word.".
Of course, here is the Java code you requested: ```java public List<CoNLLWord> findChildren(CoNLLWord word) { List<CoNLLWord> result = new LinkedList<CoNLLWord>(); for (CoNLLWord other : this) { if (other.HEAD == word) result.add(other); } return ...
Create a Java method that does the following: "Find all children of a given word.".
Of course, here is the Java code you requested: ```java private static LinearModel trainAveragedPerceptron(Instance[] instanceList, FeatureMap featureMap, int maxIteration) { float[] parameter = new float[featureMap.size()]; double[] sum = new double[featureMap.size()]; int[] time = new int...
Create a Java method that does the following: "Train Averaged Perceptron model.".
Of course, here is the Java code you requested: ```java public BinaryClassificationFMeasure evaluate(String corpus) { Instance[] instanceList = readInstance(corpus, model.featureMap); return evaluate(instanceList); } ``` Hope this helps!
Create a Java method that does the following: "Evaluate the binary classification FMeasure for a corpus".
Of course, here is the Java code you requested: ```java public BinaryClassificationFMeasure evaluate(Instance[] instanceList) { int TP = 0, FP = 0, FN = 0; for (Instance instance : instanceList) { int y = model.decode(instance.x); if (y == 1) { ...
Create a Java method that does the following: "Evaluate the binary classification of the given instance list.".
Of course, here is the Java code you requested: ```java protected static void addFeature(String feature, FeatureMap featureMap, List<Integer> featureList) { int featureId = featureMap.idOf(feature); if (featureId != -1) featureList.add(featureId); } ``` Hope this helps!
Create a Java method that does the following: "Add a feature to the list of featureIds.".
Of course, here is the Java code you requested: ```java public boolean add(E e) { if (queue.size() < maxSize) { // 未达到最大容量,直接添加 queue.add(e); return true; } else { // 队列已满 E peek = queue.peek(); if (queue.comparator().compare(e...
Create a Java method that does the following: "Add an element to the list of unique attributes.".
Of course, here is the Java code you requested: ```java void normalize() { double nrm = norm(); for (Map.Entry<Integer, Double> d : entrySet()) { d.setValue(d.getValue() / nrm); } } ``` Hope this helps!
Create a Java method that does the following: "Normalize the result of this map.".
Of course, here is the Java code you requested: ```java void multiply_constant(double x) { for (Map.Entry<Integer, Double> entry : entrySet()) { entry.setValue(entry.getValue() * x); } } ``` Hope this helps!
Create a Java method that does the following: "Multiplies the value of all the attributes of the CIS object by a constant value.".
Of course, here is the Java code you requested: ```java static double inner_product(SparseVector vec1, SparseVector vec2) { Iterator<Map.Entry<Integer, Double>> it; SparseVector other; if (vec1.size() < vec2.size()) { it = vec1.entrySet().iterator(); other = ...
Create a Java method that does the following: "Get the inner product of two vectors.".
Of course, here is the Java code you requested: ```java double cosine(SparseVector vec1, SparseVector vec2) { double norm1 = vec1.norm(); double norm2 = vec2.norm(); double result = 0.0f; if (norm1 == 0 && norm2 == 0) { return result; } else ...
Create a Java method that does the following: "Cosine of two vectors.".
Of course, here is the Java code you requested: ```java public static List<List<Term>> seg2sentence(String text) { List<List<Term>> sentenceList = SEGMENT.seg2sentence(text); for (List<Term> sentence : sentenceList) { ListIterator<Term> listIterator = sentence.listIterator(); ...
Create a Java method that does the following: "seg2sentence This method is used to convert a text to a list of lists of lists of lists of lists of terms.".
Of course, here is the Java code you requested: ```java public static List<List<Term>> seg2sentence(String text, boolean shortest) { return SEGMENT.seg2sentence(text, shortest); } ``` Hope this helps!
Create a Java method that does the following: "seg2sentence - returns a list of lists of terms from a sentence.".
Of course, here is the Java code you requested: ```java public static List<List<Term>> seg2sentence(String text, Filter... filterArrayChain) { List<List<Term>> sentenceList = SEGMENT.seg2sentence(text); for (List<Term> sentence : sentenceList) { ListIterator<Term> listIterator =...
Create a Java method that does the following: "seg2sentence This method is used to convert a text into a list of lists of lists of lists of lists of terms.".
Of course, here is the Java code you requested: ```java public static List<List<Term>> seg2sentence(String text) { List<List<Term>> resultList = new LinkedList<List<Term>>(); { for (String sentence : SentencesUtil.toSentenceList(text)) { resultList.add(segmen...
Create a Java method that does the following: "seg2sentence - returns a list of lists of lists of terms.".
Of course, here is the Java code you requested: ```java @Override public String classify(String text) throws IllegalArgumentException, IllegalStateException { Map<String, Double> scoreMap = predict(text); return CollectionUtility.max(scoreMap); } ``` Hope this helps!
Create a Java method that does the following: "Classify a single phrase.".
Of course, here is the Java code you requested: ```java String readWord(BufferedReader raf) throws IOException { while (true) { // check the buffer first if (wbp < wordsBuffer.length) { return wordsBuffer[wbp++]; } String ...
Create a Java method that does the following: "readWord returns the next word from the reader".
Of course, here is the Java code you requested: ```java public int getTermFrequency(String term) { TermFrequency termFrequency = trieSingle.get(term); if (termFrequency == null) return 0; return termFrequency.getValue(); } ``` Hope this helps!
Create a Java method that does the following: "Gets the term frequency.".
Of course, here is the Java code you requested: ```java public double computeLeftEntropy(PairFrequency pair) { Set<Map.Entry<String, TriaFrequency>> entrySet = trieTria.prefixSearch(pair.getKey() + LEFT); return computeEntropy(entrySet); } ``` Hope this helps!
Create a Java method that does the following: "Compute the entropy of the left term of a pair.".
Of course, here is the Java code you requested: ```java public void compute() { entrySetPair = triePair.entrySet(); double total_mi = 0; double total_le = 0; double total_re = 0; for (Map.Entry<String, PairFrequency> entry : entrySetPair) { PairFrequency ...
Create a Java method that does the following: "Compute the CIS language.".
Of course, here is the Java code you requested: ```java public boolean learn(String segmentedTaggedSentence) { Sentence sentence = Sentence.create(segmentedTaggedSentence); return learn(sentence); } ``` Hope this helps!
Create a Java method that does the following: "This method is used to learn a single class from a sentence.".
Of course, here is the Java code you requested: ```java public boolean load(String path) { trie = new DoubleArrayTrie<V>(); long start = System.currentTimeMillis(); if (loadDat(ByteArray.createByteArray(path + BIN_EXT))) { return true; } TreeMap<String, V...
Create a Java method that does the following: "Load a single language file.".
Of course, here is the Java code you requested: ```java protected boolean loadDat(ByteArray byteArray) { V[] valueArray = loadValueArray(byteArray); if (valueArray == null) { return false; } return trie.load(byteArray.getBytes(), byteArray.getOffset(), valueArray...
Create a Java method that does the following: "Load a single SECTYPE from the byte array.".
Of course, here is the Java code you requested: ```java public static boolean saveObjectTo(Object o, String path) { try { ObjectOutputStream oos = new ObjectOutputStream(IOUtil.newOutputStream(path)); oos.writeObject(o); oos.close(); } catch (IOEx...
Create a Java method that does the following: "Save object to a file".
Of course, here is the Java code you requested: ```java public static Object readObjectFrom(String path) { ObjectInputStream ois = null; try { ois = new ObjectInputStream(IOUtil.newInputStream(path)); Object o = ois.readObject(); ois.close(); ...
Create a Java method that does the following: "read object from file".
Of course, here is the Java code you requested: ```java public static String readTxt(String path) { if (path == null) return null; try { InputStream in = IOAdapter == null ? new FileInputStream(path) : IOAdapter.open(path); byte[] fileContent = ne...
Create a Java method that does the following: "read txt file".
Of course, here is the Java code you requested: ```java public static boolean saveTxt(String path, String content) { try { FileChannel fc = new FileOutputStream(path).getChannel(); fc.write(ByteBuffer.wrap(content.getBytes())); fc.close(); } catch...
Create a Java method that does the following: "SaveTxt 到 path".
Of course, here is the Java code you requested: ```java public static byte[] readBytesFromOtherInputStream(InputStream is) throws IOException { ByteArrayOutputStream data = new ByteArrayOutputStream(); int readBytes; byte[] buffer = new byte[Math.max(is.available(), 4096)]; // 最低4KB的缓冲区 ...
Create a Java method that does the following: "readBytesFromOtherInputStream This method is used to read bytes from other input stream.".
Of course, here is the Java code you requested: ```java public static LinkedList<String> readLineListWithLessMemory(String path) { LinkedList<String> result = new LinkedList<String>(); String line = null; boolean first = true; try { BufferedReader bw = new Buffer...
Create a Java method that does the following: "Read line list with less memory.".
Of course, here is the Java code you requested: ```java public static String dirname(String path) { int index = path.lastIndexOf('/'); if (index == -1) return path; return path.substring(0, index + 1); } ``` Hope this helps!
Create a Java method that does the following: "Get the directory name of a path.".
Of course, here is the Java code you requested: ```java public static BufferedWriter newBufferedWriter(String path) throws IOException { return new BufferedWriter(new OutputStreamWriter(IOUtil.newOutputStream(path), "UTF-8")); } ``` Hope this helps!
Create a Java method that does the following: "Create a buffered writer for a file.".
Of course, here is the Java code you requested: ```java public static BufferedReader newBufferedReader(String path) throws IOException { return new BufferedReader(new InputStreamReader(IOUtil.newInputStream(path), "UTF-8")); } ``` Hope this helps!
Create a Java method that does the following: "Create a buffered reader from a file path.".
Of course, here is the Java code you requested: ```java public static OutputStream newOutputStream(String path) throws IOException { if (IOAdapter == null) return new FileOutputStream(path); return IOAdapter.create(path); } ``` Hope this helps!
Create a Java method that does the following: "Create an OutputStream for a file.".
Of course, here is the Java code you requested: ```java public static String getSuffix(String name, String delimiter) { return name.substring(name.lastIndexOf(delimiter) + 1); } ``` Hope this helps!
Create a Java method that does the following: "Get the suffix of a class file name.".
Of course, here is the Java code you requested: ```java public static void writeLine(BufferedWriter bw, String... params) throws IOException { for (int i = 0; i < params.length - 1; i++) { bw.write(params[i]); bw.write('\t'); } bw.write(params[params.length -...
Create a Java method that does the following: "Write a line of a Sequence of Attributes.".
Of course, here is the Java code you requested: ```java public static TreeMap<String, CoreDictionary.Attribute> loadDictionary(String... pathArray) throws IOException { TreeMap<String, CoreDictionary.Attribute> map = new TreeMap<String, CoreDictionary.Attribute>(); for (String path : pathArray) ...
Create a Java method that does the following: "Load a list of CoreDictionary. Attribute objects from a file array.".
Of course, here is the Java code you requested: ```java public Edge getEdge(Node from, Node to) { // 首先尝试词+词 Attribute attribute = get(from.compiledWord, to.compiledWord); if (attribute == null) attribute = get(from.compiledWord, WordNatureWeightModelMaker.wrapTag(to.label)); if (at...
Create a Java method that does the following: "Get edge from two nodes.".
Of course, here is the Java code you requested: ```java public List<Map.Entry<String, Float>> analogy(String A, String B, String C) { return analogy(A, B, C, 10); } ``` Hope this helps!
Create a Java method that does the following: "Analogy method for the segment.".
Of course, here is the Java code you requested: ```java public static List<String> to863(List<Term> termList) { List<String> posTagList = new ArrayList<String>(termList.size()); for (Term term : termList) { String posTag = posConverter.get(term.nature.toString()); if...
Create a Java method that does the following: "To 863 List of Terms".
Of course, here is the Java code you requested: ```java final public Vector vector(K key) { Vector vector = storage.get(key); if (vector == null) return null; return vector; } ``` Hope this helps!
Create a Java method that does the following: "Get a single record vector from the cache.".
Of course, here is the Java code you requested: ```java public float similarity(K what, K with) { Vector vectorWhat = storage.get(what); if (vectorWhat == null) { return -1f; } Vector vectorWith = storage.get(with); if (vectorWith == null) { ...
Create a Java method that does the following: "Gets the similarity of two terms of a set of terms.".
Of course, here is the Java code you requested: ```java public List<Map.Entry<K, Float>> nearest(K key, int size) { Vector vector = storage.get(key); if (vector == null) { return Collections.emptyList(); } return nearest(key, vector, size); } ``` Hope this h...
Create a Java method that does the following: "Returns the nearest set of attributes of the specified key to the specified size.".
Of course, here is the Java code you requested: ```java public List<Map.Entry<K, Float>> nearest(Vector vector, int size) { MaxHeap<Map.Entry<K, Float>> maxHeap = new MaxHeap<Map.Entry<K, Float>>(size, new Comparator<Map.Entry<K, Float>>() { @Override public int compare(Map....
Create a Java method that does the following: "Get the nearest list of entries in the storage.".
Of course, here is the Java code you requested: ```java public List<Map.Entry<K, Float>> nearest(Vector vector) { return nearest(vector, 10); } ``` Hope this helps!
Create a Java method that does the following: "Returns the nearest entry of the vector to this class.".
Of course, here is the Java code you requested: ```java public List<Map.Entry<K, Float>> nearest(K key) { return nearest(key, 10); } ``` Hope this helps!
Create a Java method that does the following: "Returns the nearest record set entry for the given key.".
Of course, here is the Java code you requested: ```java final List<Map.Entry<K, Float>> queryNearest(String query, int size) { if (query == null || query.length() == 0) { return Collections.emptyList(); } try { return nearest(query(query), size); ...
Create a Java method that does the following: "Query nearest.".
Of course, here is the Java code you requested: ```java public final List<Pair<String, Double>> predict(String[] context) { List<Pair<String, Double>> result = new ArrayList<Pair<String, Double>>(outcomeNames.length); double[] p = eval(context); for (int i = 0; i < p.length; ++i) { ...
Create a Java method that does the following: "Predict a sequence of attributes of a Sequence.".
Of course, here is the Java code you requested: ```java public final List<Pair<String, Double>> predict(Collection<String> context) { return predict(context.toArray(new String[0])); } ``` Hope this helps!
Create a Java method that does the following: "Predict a sequence of tokens in a collection of tokens.".
Of course, here is the Java code you requested: ```java public static MaxEntModel create(ByteArray byteArray) { MaxEntModel m = new MaxEntModel(); m.correctionConstant = byteArray.nextInt(); // correctionConstant m.correctionParam = byteArray.nextDouble(); // getCorrectionParameter ...
Create a Java method that does the following: "Create a MaxEntModel from the given byte array.".
Of course, here is the Java code you requested: ```java void clear() { documents_.clear(); composite_.clear(); if (centroid_ != null) centroid_.clear(); if (sectioned_clusters_ != null) sectioned_clusters_.clear(); sectioned_gain_ = 0.0; } ``` Ho...
Create a Java method that does the following: "Clear all the records in the SECTYPE.".
Of course, here is the Java code you requested: ```java SparseVector centroid_vector() { if (documents_.size() > 0 && composite_.size() == 0) set_composite_vector(); centroid_ = (SparseVector) composite_vector().clone(); centroid_.normalize(); return centroid_; } ```...
Create a Java method that does the following: "Returns the centroid vector.".
Of course, here is the Java code you requested: ```java void add_document(Document doc) { doc.feature().normalize(); documents_.add(doc); composite_.add_vector(doc.feature()); } ``` Hope this helps!
Create a Java method that does the following: "Adds a document to the document set.".
Of course, here is the Java code you requested: ```java void remove_document(int index) { ListIterator<Document<K>> listIterator = documents_.listIterator(index); Document<K> document = listIterator.next(); listIterator.set(null); composite_.sub_vector(document.feature()); } ```...
Create a Java method that does the following: "Removes a document from the composite.".
Of course, here is the Java code you requested: ```java void remove_document(Document doc) { for (Document<K> document : documents_) { if (document.equals(doc)) { remove_document(doc); return; } } } ``` Hope this helps...
Create a Java method that does the following: "Remove a document from the list of documents_.".
Of course, here is the Java code you requested: ```java void choose_smartly(int ndocs, List<Document> docs) { int siz = size(); double[] closest = new double[siz]; if (siz < ndocs) ndocs = siz; int index, count = 0; index = random.nextInt(siz); // initial cente...
Create a Java method that does the following: "Choose a single language from the list of documents.".
Of course, here is the Java code you requested: ```java void section(int nclusters) { if (size() < nclusters) return; sectioned_clusters_ = new ArrayList<Cluster<K>>(nclusters); List<Document> centroids = new ArrayList<Document>(nclusters); // choose_randomly(nclusters,...
Create a Java method that does the following: "Section the document set.".
Of course, here is the Java code you requested: ```java public static void parsePattern(List<NT> ntList, List<Vertex> vertexList, final WordNet wordNetOptimum, final WordNet wordNetAll) { // ListIterator<Vertex> listIterator = vertexList.listIterator(); StringBuilder sbPattern = new StringBuilder(nt...
Create a Java method that does the following: "Parse pattern.".
Of course, here is the Java code you requested: ```java public static <TERM> Map<TERM, Double> tf(Collection<TERM> document, TfType type) { Map<TERM, Double> tf = new HashMap<TERM, Double>(); for (TERM term : document) { Double f = tf.get(term); if (f == null) f = 0....
Create a Java method that does the following: "Get a map of terms to counts for a given type of document.".
Of course, here is the Java code you requested: ```java public static <TERM> Map<TERM, Double> tf(Collection<TERM> document) { return tf(document, TfType.NATURAL); } ``` Hope this helps!
Create a Java method that does the following: "Gets the NUCENT language terms.".
Of course, here is the Java code you requested: ```java public static <TERM> Iterable<Map<TERM, Double>> tfs(Iterable<Collection<TERM>> documents) { return tfs(documents, TfType.NATURAL); } ``` Hope this helps!
Create a Java method that does the following: "Returns an iterable of map of term to distance from the document to the document.".
Of course, here is the Java code you requested: ```java public static <TERM> Map<TERM, Double> idf(Iterable<Iterable<TERM>> documentVocabularies, boolean smooth, boolean addOne) { Map<TERM, Integer> df = new HashMap<TERM, Integer>(); int d = smooth ? 1...
Create a Java method that does the following: "Get a map of term - > value pairs for a Sequence.".
Of course, here is the Java code you requested: ```java public static <TERM> Map<TERM, Double> idf(Iterable<Iterable<TERM>> documentVocabularies) { return idf(documentVocabularies, true, true); } ``` Hope this helps!
Create a Java method that does the following: "Create a map of terms to their corresponding scores.".