Which Iterator To Be Use To Create Instances From Feature Value Pairs (Mallet API)

Mar 12, 2015

I am tring to run LDA to generate some topics from txt files as the following one:

Document1 label1 forest=3.4 tree=5 wood=2.85 hammer=1 colour=1 leaf=1.5
Document2 label2 forest=10 tree=5 wood=2.75 hammer=1 colour=4 leaf=1
Document3 label3 forest=19 tree=0.90 wood=2 hammer=2 colour=9 leaf=4.3
Document4 label4 forest=4 tree=5 wood=10 hammer=1 colour=6 leaf=3

Each numeric value in the file is an indication of the number of occurrences of each feature (e.g., forest, tree) multiplied by a given penalty. To generate instances from such a file, I use the following Java code:

String lineRegex = "^(S*)[s,]*(S*)[s,]*(.*)$";
String dataRegex = "[p{L}([0-9]*.[0-9]+|[0-9]+)_=]+";
InstanceList generateInstances(String dataPath) throws UnsupportedEncodingException, FileNotFoundException {
ArrayList<Pipe> pipeList = new ArrayList<Pipe>();
pipeList.add(new Target2Label());

[Code] .....

I then add the so-generated instances to my model using the instruction model.addInstances(generatedInstances). The resulting output is described below.

It contains errors caused by the instruction model.addInstances(generatedInstances). Debugging my code showed me that the alphabet associated to the model is null. Am I using the wrong iterator?

name: document1
target: label1
input: TokenSequence [forest=3.4 feature(forest)=3.4 span[0..10], tree=5 feature(tree)=5.0 span[11..17], wood=2.85 feature(wood)=2.85 span[18..27], hammer=1 feature(hammer)=1.0 span[28..36], colour=1 feature(colour)=1.0 span[37..45], leaf=1.5 feature(leaf)=1.5 span[46..54]]
Token#0:forest=3.4 feature(forest)=3.4 span[0..10]

[Code] ....

View Replies


ADVERTISEMENT

How To Create Withdraw / Deposit Feature So It Can't Exceed Maximum Limit

Nov 25, 2014

So lets say I got maximum of 20 deposit, I want to create a method/function (idk what proper name for it is) so that you cannot deposit more than 20 nor withdraw more than you have in your account, so this function checks your account, if your total is for example 18 and you're trying to deposit 10, it rejects it and doesn't add to your total and pops up with a message, vice versa for withdraw.

This is what I have so far

Not I already have the maximum limit + total feature created just not displayed here

public void depositMoney (int dMoney) {
if(DMoney > 0 ) {
totalMoney = totalMoney + dMoney;
}
else {
System.out.println("Please insert money more than 0");

[Code] .....

View Replies View Related

How To Create Withdraw / Deposit Feature So It Cannot Exceed Maximum Limit (read)

Nov 25, 2014

So lets say I got maximum of 20 deposit, I want to create a method/function (idk what proper name for it is) so that you cannot deposit more than 20 nor withdraw more than you have in your account, so this function checks your account, if your total is for example 18 and you're trying to deposit 10, it rejects it and doesn't add to your total and pops up with a message, vice versa for withdraw.

This is what I have so far . Not I already have the maximum limit + total feature created just not displayed here

Java Code:

public void depositMoney (int dMoney) {
if(DMoney > 0 ) {
totalMoney = totalMoney + dMoney;
} else {
System.out.println("Please insert money more than 0");

[Code] ....

View Replies View Related

Use Data Read From File To Create Instances?

Sep 10, 2014

"Write a program (save the program as ProductInventory.java) that will read data about 5 products from a text file (Products.txt. The program should use the data read from the file to create instances (objects) of Product.java(Use Product class as a Reference Type)."

I'm yet to discover how I will get the info from the textfile using scanners but I don't know how to "create instances of a reference type".

This is the code of Product.java that came with the exercise.

public class Product {
private String productCode = "";
private String productName = "";
private int quantity;
private String supplierName = "";
private String supplierAddress = "";
private double price;

[Code] .....

By the way, the exercise also required me to use the abstract class ProductLister. To be clearer, the text file is kinda like this:

54643
Rizer Mouse
Mark5s Merchandising
Marquee Mall
4
205.50
23412
Acer Ultrabook
JohnJade Merchandise
Cornal City
2
62200.00
93112
Dell Ultrabook
Octagon Marketing
Cornal City
3
68900.00
22126
Macbook Air Pro
Computerware Services
San Beda, Chad
2
93500.00

View Replies View Related

Use Applet To Create Two Instances Of Employee Class

Jan 9, 2014

What I have to do: Use Applet to create two instances of the Employee class. Display the data on the Graphics object. Display in the applet the names and values of all of the instance variables in each instance of the class. Also display the value of any static variables.

What I'm doing:

import java.applet.Applet;
import java.awt.*;
public class EmployeeApplet extends Applet {
public static int topSalary = 195000;
int hoursPerWeek;
public static void setTopSalary (int s) {
if (s > topSalary)

[Code]...

I'm not able to display hours per week for e1 and e2.

View Replies View Related

Create Two Instances Of Class And Test Each Of Methods

Nov 1, 2014

How do I use two constructors and I'm having trouble with using char for gender...

Write a program to test the Person class defined below. Your test program should create two instances of the class (each to test a different constructor) and test each of the methods. You are also required to illustrate the error in trying to access private data members from the client class (for clarity temporarily change the private modifier to public and test again). See screenshots below for sample output.

The screen shots are displayed as:

p1 name = Not Given Age = 0 Gender = U
p2 name = Jane Doe Age = 0 Gender = F
p1 name = John Doe Age = 25 Gender = M

and

PersonTester.jave:20: name has private access in Person
System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender);
 PersonTester.jave:20: age has private access in Person
System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender);
  PersonTester.jave:20: gender has private access in Person
System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender);
 
3 errors

Here is the class given :

class Person {
// Data Members
private String name; // The name of this person
private int age; // The age of this person
private char gender; // The gender of this person
 
[Code] .....

View Replies View Related

JavaFX 2.0 :: Why Does Scene Builder Constantly Create New Instances Of Nodes

Nov 28, 2014

I thought I had a simple idea for creating a control that would let me get some of the behavior of a card pane.  This is the entire control:
 
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;

[Code] ....
 
The idea is pretty simple; extend StackPane, add an active property, bind the visible and managed properties of the pane to the active property, and, whenever the active property is changed to true, iterate sibling nodes de-activating any siblings that are also of the type Card.
 
However, this doesn't work with Scene Builder.  While trying to debug, I created an ExtStackPane:
 
import javafx.collections.ListChangeListener;
import javafx.scene.Node;
import javafx.scene.layout.StackPane;
public class ExtStackPane extends StackPane {
    {
        getChildren().addListener((ListChangeListener<Node>) c -> {
            System.out.println("ExtStackPane children change: " + c.toString());
        });
    }
}
 
All this does is log list change events.  However, I was very surprised by the output when working in Scene Builder.  I added both controls to Scene Builder and did the following:
 
0) Added an ExtStackPane
1) Added a Card to the ExtStackPane
2) Added another Card to the ExtStackPane
3) Added a Label to the first Card
4) Added a Label to the second Card
5) Changed the text of the first Label to Hello
6) Changed the text of the second Label to World
7) Set the first Card to active
8) Set the second Card to active
 
I get the following output:
 
1)
ExtStackPane children change: { [Card@5b9067b3] added at 0 }

2)
ExtStackPane children change: { [Card@6b6328bd] added at 0 }
ExtStackPane children change: { [Card@6aca8cc5] added at 1 }

[Code] ....
 
This is what things look like in Scene Builder:
 
Does Scene Builder recreate the entire hierarchy every time I make a small change?  Here's an application that does the same as the manual steps I performed in Scene Builder:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class CardApplication extends Application {

[Code] ....

The output when running the above is:

1)
ExtStackPane children change: { [Card@6dfaa767] added at 0 }

2)
ExtStackPane children change: { [Card@6aa2c411] added at 1 }

[Code] ....
 
The behavior is obviously a lot different than when I'm working with the control in Scene Builder. What Scene Builder is doing to change the behavior of my Card control so much?  Does my Card control break some rule(s) I'm not aware of?

View Replies View Related

Reading Pairs Of Lines From A File?

Jul 19, 2014

This what the data file looks like -

5165168416516988798484984984984984
9898798798798

1556516846516518498
51688484979789798798798491

The problem was to make code which will combine consecutive lines which contain some data into one line and print it. I made a solution that works.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Filez {
public static void main(String[] args) {
File file = null;

[code]...

View Replies View Related

Parsing Text File That Contains Pairs

May 9, 2015

I thought of processing line by line using scanner and then split each line in the ":" . But then i stuck, i only need the right part of the ":" so that i can save it to a class e.g. John Doe, 133456593, married etc.

Java Code: Name: John Doe
TRN: 133456593
Status: Married
Income: 22500
Receipts:

Receipt ID: 1
Date: 25/2/2014
Kind: Basic
Amount: 2000
Company: Hand Made Clothes
Country: UK
City:London
Street: Cambridge
Number: 10

Receipt ID: 2
Date: 28/2/2014
Kind: Entertainment
Amount: 500
Company: Floca Cafe
Country: Italy
City: Rome
Street: Piazza
Number: 4 mh_sh_highlight_all('java');

View Replies View Related

NullPointException - Creating Pairs From Arrays

Oct 9, 2014

So in my java class we are suppose to ask for how many names are going to be entered, create an array of that length, and then store that many inputted names. We then take those names, alphabetize them, and create a set of pairs. For example, it might look like this:

How many people are there? 4
Please enter the names of those people:
Dana
Bob
Alice
Charlie

There are 6 possible pairings. They are:
Alice & Bob
Alice & Charlie
Alice & Dana
Bob & Charlie
Bob & Dana
Charlie & Dana

We are also suppose to account for less than two names (both 1 and 0 as well as negatives).

I keep getting a null point exception error and I can't figure out why. Even debugging in Eclipse doesn't give any pointers except that it is originating in line 76.

import java.util.Scanner;
import java.util.Arrays;
class partners
{
public static int numNames;
public static int numPairs;

[Code] .....

View Replies View Related

JSP :: Generate Hashtable And Display Its Key Value Pairs Back To Browser - How To Prevent Timeout

Jun 24, 2004

I have a jsp page that generate a hashtable and display its key-value pairs back to the browser. The problem is that it takes on an average about 15 minutes to build this hashtable, and as a result, I always get a timeout error. What can I do to avoid getting the timeout error without changing the server configuration for timeout

View Replies View Related

How To Implement UNDO Feature

Mar 10, 2014

I need to design 'notepad' application as my assignment.

Requirement: Only text is allowed, all the characters are having same size and font. It should have feature like new, open, save , save as , exit , UNDO , find , replace and font.

For this i use JTextArea and menu bar .

I am able to develop features like new, open, save , save as , exit. Need to implement now UNDO , find , replace and font but struck at 'UNDO'.

UNDO feature should be enable only when user writing in the writing area but not when it opens any file. What i thought is to have a flag on whenever user save whatever he wrote and if he use select UNDO then it check for the flag. If flag is ON then it will not do UNDO and if flag is not set then it cleared everything from the Text Area.

View Replies View Related

Web Services :: Add Uploading Image Feature To Form

Apr 21, 2015

I'm using json to submit form from web and mobile, I want to add uploading image feature to this form. How can I do that with code if possible?

View Replies View Related

JSF :: Export To Excel With Indexing Feature With Icefaces 1.8.2

Feb 24, 2014

As of now am using icefaces 1.8.2 provided tags for downloading data into excel sheet where i can download all the data from a data table. But now the requirement is like need to download the data into excel sheet based on values passed from UI as parameters to the action class method.

Attaching the code snippet along with this post.

CustomerList.xhtml :-
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<ice:outputLabel value="Export:" />

[Code] ....

View Replies View Related

Erasure Feature From Generics - Duplicated Bound Error

Jun 14, 2014

The erasures of all constituent types of a bound must be pairwise different, or a compile-time error occurs.

Well I know what type erasure is, and I think I kind got what this statement means. My understanding from it is that if your type parameter has more than one bound and those bounds occurs to be the same type after erasure that is a compile-time error. Is that it?

The only thing I could found related is something like this:

class A<T extends List<Integer> & List<Integer>>{
}

Which as you might know gives the Duplicated bound error.

View Replies View Related

Servlets :: Feature Detection - Determine Browser Type

Apr 22, 2014

I need to be able to detect IE 9, IE 10, IE 11 and the latest from Firefox and Chrome. The old method using the user-agent string is unreliable and not recommended. There is a different approach called, "Feature Detection". But I need to know what features to test to determine the browser. I can write it myself, or if there is a handy dandy API using feature detection already written that would be OK too.

View Replies View Related

Iterator Next Not Working In If

Apr 4, 2014

I need to find out if one array list is a sub-sequence of another. The elements in the first list all need to be in the second list and must be in the same order. So s1<n, t, a> is a sub-sequence of s2<q, n, f, r, t, d, a>, but s1<a, a, t> is not a sub-sequence of s2<a, t, a>. I need to use iterators to go through each list, and I should only go through each list once (since it has to be in the same order) so nested loops don't seem like they would work because it would start at the beginning of one list every time it moved to another element in the outer loop's list.I seem to have an issue where the itr1. next()
is ignored when in an if statement.

My current code just stalls and will never stop running. I've also switched things around and put the not equal check after the if it is equal and it throws a NoSuchElementException.

import dataStructures.*;
public class Subsequence3
{
public static void main(String[] args)
{
ArrayList<Character> s1 = new ArrayList<Character>();
s1.add('n');
s1.add('p');
s1.add('a');

[code]....

View Replies View Related

Using Iterator To Add To Arraylist

Nov 12, 2014

I am trying to add the contents of the iterator to an arraylist so I can do other stuff to it, however I am getting an error when I actually try adding it to the list, stating that

"The method add(Map.Entry<String,myObject>) in the type ArrayList<Map.Entry<String,myObject>> is not applicable for the arguments (myObject)"

Here is what I have tried doing:

Iterator<Map.Entry<String, myObject>> iterator = hash.entrySet().iterator();//hash is my HashMap object
ArrayList<Map.Entry<String, myObject>> list = new ArrayList<Map.Entry<String, myObject>>();
while(iterator.hasNext()){
Map.Entry<String, myObject> entry = iterator.next();
list.add(entry.getValue());//error here
}

View Replies View Related

How To Use Iterator Instead Of Foreach Loop

Mar 25, 2015

I am trying to use an iterator instead of a foreach loop to go through a list of inventories to see if a car is rearDrive and count how many are rearDrive but somehow I seem to be missing something that the counter isn't working as expected.

public int howManyAreRearWheelDrive(){
int i = 0;
int counter = 0;
int inventSize = inventory.size()-1;
while(i < inventSize){
boolean wheelDrive = inventory.get(i).getIsRearWheelDrive();
if( wheelDrive == true){
counter++;
}
}
return counter; // returning here doesn't give me anything
}

View Replies View Related

Why Iterator Should Be Inner Class In Collections

Feb 24, 2014

The Iteratior provides the functionality of traversing and removal which we can achieve through normal for loop and remove() of the data structure.Then, why do we need Iterator explicitly and as an inner class?

View Replies View Related

Cannot Return Object Of Iterator As Its An Interface

Mar 3, 2014

What does the iterator() method return???it can't return an object of Iterator as it's an interface...

View Replies View Related

Creating Custom Fail-fast Iterator?

Feb 8, 2015

As part of a homework assignment in my 1st Java Class, I am creating my own Circular Generic LinkedList and Array class. My class uses the Queue Interface Extends Iterable but I am creating my own methods to work with. For the most part, I believe I have been successful in creating the class aside from one method. That method is the Iterator<E> iterator().

/**
* Return a fail-fast iterator, which throw a java.util.ConcurrentModificationException
* if the client modifies the collection (via enqueue(...) or dequeue()) during iteration.
*/
@Override
public Iterator<E> iterator() {

I don't understand how an iterator, let alone a "fail-fast" iterator ties into my project. I've spent hours reading up on a way to imploy my own generic fail-fast iterator but to no avail.

I feel like I could come up with some workable code if I knew what the point is to useing a user-defined, non Java Library iterator is to do.

As well, does throwing a ConcurrentModificationException require a try and catch block?

View Replies View Related

Linked List Iterator Remove Implementation

May 3, 2014

I have a problem with a linked list iterator, my problem is implementing the iterator.remove method given the following code:

package mapsql.util;
import java.util.Iterator;
public class LinkedList<T> implements List<T> {
private class Node implements Position<T> {
T element;
Node next, prev;
public Node(T element) {
this.element = element;

[Code] ....

View Replies View Related

Print A Blank Line After Certain Specific Points In Iterator

Feb 17, 2015

I have the following HashMap:

// 2009
nobelPrizeWinners.put("2009 Physics",
new PrizeWinner[] {new PrizeWinner("Charles K.", "Kao"),
new PrizeWinner("Willard S.", "Boyle"), new PrizeWinner("George S.", "Smith")});
nobelPrizeWinners.put("2009 Chemistry",
new PrizeWinner[] {new PrizeWinner("Venkatraman", "Ramakrishnan"),

[Code] .....

At the moment, my output is:

2008: Chemistry: Osamu Shimomura, Martin Chalfie, Roger Y. Tsien
2008: Economics: Paul Krugman
2008: Literature: Jean-Marie Gustave Le Clézio
2008: Medicine: Harald zur Hausen, Françoise Barré-Sinoussi, Luc Montagnier
2008: Peace: Martti Ahtisaari

[Code] .....

However, I need a blank line between the final entry of 2008 and the first entry of 2009.

View Replies View Related

Double Circular Linked List - Implementing Iterator

Oct 14, 2014

My homework is a Double Circular Link list and when i write implements Iterator it gives me a an error when I compile it the same for my subset method...

ERRORS :DoublyCircularList.java:55: error: DoublyCircularList.iterator is not abstract and does not override abstract method remove() in Iterator public class iterator implements Iterator<T>
^
Note: DoublyCircularList.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

import java.util.Iterator;
public class DoublyCircularList<T extends Comparable<T>> extends LinkedList<T>implements Iterable<T>
{
Node<T> first;
int size;
public DoublyCircularList(){
first = null;
size = 0;

[code]....

View Replies View Related

List Iterator Execution - Traversing In Forward Direction

Nov 5, 2014

List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 5; i++) {
list.add(i * 3);
}
ListIterator<Integer> listItr = list.listIterator();
System.out.println("Traversing in a forward direction");

[Code] ....

Output:--

Traversing in a forward direction
0 3 6 9 12
Traversing in a backward direction
12 9 6 3 0 425

Why 425 is not showing when we are traversing in a forward direction.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved