How to compare each item in a Stack with the next one??

I am trying to compare each string value with the next one in a stack.
I think I am doing something wrong when I store the poped string in a temp?
Object is:
-----to read in a stack and compare each element. We are looking for an "adj" next to a" NP*".
-----if we find a "adj" next to a "NP*" then we need to remove the "adj" and push the "NP*" on a new stack.
-----if we find something other than an "adj" next to a "NP*" then we just need to push that item on the new stack
we continue through the stack until it is empty.
-----once we have checked the entire stack for "adj" next to "NP*" and changed them all, we need to send the new stack back to the method for another test.
-----this time we are looking for a "det" next to a "NP*"
-----if we find
---------remove the "det" and change the "NP*" to "NP"
there are more test after that one but, if I can get here I think I can get through the rest.
In all this is a grammar checking program, checking for correct english.
thanks for the help, my mind feels like mush a new perspective will help,
steven
Here is what I have so far:
public void structureCheck(Stack s, int wordCount, boolean inOrder)throws EmptyStackException{
          Stack orderStack = new Stack();
          int parseCount =0;
          boolean display = false;
          int count = 0;
               if(inOrder == false){     
                    for(int i=0; i<wordCount;i++){                                        
                         String temp = ""+s.pop();
                              if(temp.equals("n")){
                                   temp = "NP*";
                         orderStack.push(temp);
                         parseCount++;          
               structureCheck(orderStack,parseCount,true);     
               if(inOrder == true){
                    parseCount= wordCount;
                    System.out.println("parseCount  "+parseCount);
                    for (Enumeration e = s.elements(); e.hasMoreElements();){
                         for(int i=0; i<parseCount; i++){
                              String temp = ""+s.pop();
                              String temp2= ""+s.pop();
                              String temp3= ""+s.pop();
                              System.out.println("temp  "+temp+"  count  "+count);
                              /*temp = temp;
                              System.out.println("temp2  "+temp+"  count  "+count);
                              temp = temp;
                              System.out.println("temp3  "+temp+"  count  "+count);*/
                              count++;
                              if((temp.equals("adj") & temp2.equals("adj") & temp3.equals("NP*"))){
                                   System.out.println("temp  "+temp+"  temp2  "+temp2+"  temp3  "+temp3);
                                   temp="NP";                                   
                              orderStack.push(temp3);
                              parseCount++;
                              /*else{     
                                   orderStack.push(temp3);
                                   parseCount++;
               //structureCheck(orderStack,parseCount,false);
               System.out.println("parseCount=  "+parseCount+" inOrderStack=  "+orderStack);
     }          

This code is different from yours. For one thing, the first part, where inOrder is false, is not included because you did not post what behavior that is supposed to perform. The code below does what you posted...it puts some Strings into a Stack, then parses the Stack. If adj is followed by NP* then adj is removed. Then the new Stack is parsed to find det followed by NP*, and det is removed while NP* is changed to NP.
import java.util.Stack;
import java.util.Vector;
public class Test {
   public static void main(String[] args) {
      Stack stack=new Stack();
      Stack stack2=new Stack();
      String[] s={"no","adj","NP*","adj","not","NP*","adj","NP*","dumb","det","NP*"};
      for(int i=s.length-1;i>-1;i--) stack.push(s);
stack=structureCheck(stack,"adj","NP*","NP*");
for(int i=stack.size()-1;i>-1;i--)
System.out.println(stack.elementAt(i));
System.out.println();
stack=structureCheck(stack,"det","NP*","NP");
for(int i=stack.size()-1;i>-1;i--)
System.out.println(stack.elementAt(i));
public static Stack structureCheck(Stack s,String tofind,String tomatch,String tochangeto) {
Stack orderStack = new Stack();
for(int i=0;i<s.size();i++) {
String str=(String) s.elementAt(i);
if(i<s.size()-1 && str.equals(tomatch) && ((String) s.elementAt(i+1)).equals(tofind)) {
i++;
orderStack.add(tochangeto);
} else
orderStack.add(str);
return orderStack;

Similar Messages

  • HT201269 Have new iPhone 5s and older iPad ( looking to buy new iPad ) question for both is should I hook them up to mu computer and back up the computer on each devise and sink and than the next one.  The second question is should I do the I pad first ca

    Have new iPhone 5s and older iPad ( looking to buy new iPad ) question for both is should I hook them up to y computer and back up the computer on each devise and sink and than the next one.  The second question is should I do the I pad first cause it has photos in my email that have not been downloaded and it is one of or is the first model

    No it's not stealing. They have an allowance that you can share with so many computers/devices. You'll have to authorize her computer to play/use anything bought on your acct. You can do this under the Store menu at top when iTunes is open on her computer.
    As far as getting it all on her computer....I think but I am not sure (because I don't use the feature) but I think if you turn on Home Sharing in iTunes it may copy the music to her computer. I don't know maybe it just streams it. If nothing else you can sign into your acct on her computer and download it all to her computer from the cloud. Not sure exactly how to go about that, I haven't had to do that yet. I wonder if once you authorize her computer and then set it up for automatic downloads (under Edit>Preferences>Store) if everything would download. Sorry I'm not much help on that.

  • How to compare, current value in :block.text_item with the database value

    Hi
    Could you please tell me
    How to compare the current value in :block.text_item with the corresponding database column value.
    I am using forms 10g
    There is block and there is an text Item in that block.
    When I run the form and query the block (tabular), the :block.text_item shows me, whatever value there in the database.
    Now I add some value in the :block.text_item to the existing value.
    now
    the :block.text_item contains old+ new added value
    whereas
    the database table contains 'old' value
    Now on a button click , I want to find out what is the value that I have added
    Could you please tell me, is it possible without writing a select query?

    Hello,
    Now on a button click , I want to find out what is the value that I have addedSo you mean always user will add value in the existing value. Because this way will fail in one case. Let say
    Value in Database is = ABCD
    User opened the form and he removed the D and write E and now value is ABCE and length is still same 4. So, there is no addition.
    Anyway you can know the database value at runtime there is one property for item called DATABASE_VALUE. It gives the value which is in database while you are running the form before save. and you can use like this..
    Trigger = WHEN-MOUSE-DOUBLE-CLICK on item level
    DECLARE
      vItemValue DATATYPE; -- Set the data type according to your desired field.
      vValueAdded DATATYPE; -- Set the data type according to your desired field.
    BEGIN
      vItemValue:=GET_ITEM_PROPERTY('ITEM_NAME',DATABASE_VALUE);  -- It will return you the database value in vItemValue variable.
      IF LENGTH(vItemValue)>LENGTH(:FORM_ITEM_NAME) THEN  -- It mean something change or added
        vValueAdded:=SUBSTR(:FORM_ITEM_NAME,LENGTH(vItemValue)+1);
        MESSAGE('Added value is : '||vValueAdded);  -- It will show you the added value.
      END IF;
      -- now suppose you want to show the old and new value in message not the added one
      -- Then no need of IF condition. You can just use message like this
      -- And i would prefer to use like this way
      MESSAGE('Old Value : '||vItemValue||'  New Value - '||:FORM_ITEM_NAME);
      MESSAGE('Old Value : '||vItemValue||'  New Value - '||:FORM_ITEM_NAME);
    END;Hope it is clear.
    -Ammad

  • Hi apple, I have the new ipad with retina display, i have however cracked the screen pretty badly. I was just wondering how much it is to replace this ipad with the same one. It is a 32gig. Thanks

    Hi apple,
    I have the new ipad (4th gen) with retina display. Yesterday I cracked the screen pretty badly. I was just wondering how much it is to replace it with the same ipad. I have the 32gig ipad with wifi.
    Thanks

    The iPad will be $329 AUD if replaced via postage service or $309 AUD if replaced at an Apple Store. Yes they will give you the replacement and take your old iPad so I would suggest if you can back it up to iTunes so that you can restore the back up to the replacement.

  • How to Compare entity instances's attribute and find the latest one.

    Hi,
    Below is my data model
    entities: the person, the job
    Relationships: the person-> the job (the person's job) 1 to M (reverse: the person's job's person)
    the person ->the job (the person's favorite job) M to M (inferred)
    Now, the job entity has below attributes: (only important ones are listed)
    1. the job's id
    2. the job's end date
    3 the job's person id
    the person entity has below attributes:(only important ones are listed)
    1. the person's id
    2. the person's most recent job id
    Using the "member of" operator I am assigning the entity instances to "the person's favourite job". Upto this things are working fine.
    Now the problem is I want to determine -"the person's most recent job id" by comparing the entity instance's attribute "the job's end date" and then getting the job Id of the same entity instance.
    Can someone help me in this..?
    thanks,

    Hi,
    Just be aware that if you had two jobs ending at the same time, then InstanceValueIf would return uncertain (perhaps they had two jobs at the same company...?) so just make sure you handle that.
    consider renaming the relationship to the plural... "the person's favourite jobs".
    I am assuming that your system only handles jobs that have ended, as things would be much more complicated if they could have multiple jobs (which could overlap) or jobs with start dates that haven't ended yet.
    Thanks,
    Ben

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • How do I delete items from "My Activity" from the Community tab..

    How do I delete items from "My Activity" from the Community tab?

    You can't. The streams are uneditable even to the mods and admins. It's an ongoing data collection. You can only hide stuff by marking it as read in the relevant areas like your Inbox.
    Mylenium

  • Compare an old report with the new one

    Hi,
    i have saved a report in Answers. Then in my cube data are changed. In Answers i re-submit request and save new report with new data. Now I would compare two reports. But when i open old report, data shown are new. So I have two identical reports. How can I compare an old report with the new one? Thanks
    Giancarlo

    ok then why don't you create two distinct reports but each with different filter value on the time column.
    so that one report will give you old results. another report will give you new results.

  • Hi,I have made a new Apple ID and logged in on my phone, on settings, but the app store is still using my old one. How do I get rid of the old ID and replace it with the new one?

    Hi, I have made a new Apple ID and logged in on my phone, settings > iTunes & app stores, but the app store is still using my old Apple ID. How do I get rid of the old ID and replace it with the new one?

    HAYDONISRAD wrote:
    ...  Maybe I'll stick with hers for now :-)
    OR...
    You could use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.
    From Here   http://support.apple.com/kb/HE37
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?

  • How to insert some strings in a query with the clausule 'in' in a procedure

    Hello fellows.
    Do you know how to insert some strings in a query with the clausule 'in' in a procedure (with a variable)?.
    I tell us my problem with an example:
    I want to use this select but introducing a variable instead the 'value1', 'value2':
    select * from table1 where field1 in ('value1', 'value2');
    if I declare the variable var1 as:
    TC_VAR1 CONSTANT VARCHAR2(50) := '''value1'',''value2'''
    and I use it as:
    select * from table1 where field1 in (TC_VAR1);
    It doesn't work because Oracle takes TC_VAR1 as an all string. I think Oracle takes it as this:
    select * from table1 where field1 in ('value1, value2');
    If I use the data type TABLE, I don't know how to use well:
    TYPE varchar2_table IS TABLE OF VARCHAR2(10);
    tb_var varchar2_table;
    select * from table1 where field1 in (tb_var);->It returns an error and there ins't an method that it returns all values.
    A curious case is that if I have a sql script (for example script1.sh) with this query:
    select * fromt able1 where field1 in (&1)
    and I invoke this script as
    script1.sh "'''value1'',''value2'''". It works
    Can anybody helps me?.
    Thanks.

    Thanks to all. Really.
    First, sorry for my English. It's horrible. Thank to all for understand it (my English).
    I've resolved my problem with these links:
    ORA-22905: cannot access rows from a non-nested table item
    and
    http://stackoverflow.com/questions/896356/oracle-error-ora-22905-cannot-access-rows-from-a-non-nested-table-item
    At last, I have used someting like this:
    DECLARE
    number_table_tmp NUM_ARRAY:=NUM_ARRAY(410673, 414303, 414454, 413977, 414042, 414115, 413972, 414104, 414062);
    BEGIN
    FOR c1 IN (SELECT par_id, 1 acc_vdo_id FROM SIG_VIS_CAM
    WHERE par_id IN (SELECT * FROM TABLE(number_table_tmp))
    UNION ALL
    SELECT par_id, 2 acc_vdo_id FROM SIG_ACCAO a
    WHERE par_id IN (SELECT * FROM TABLE(number_table_tmp))) LOOP
    NULL;
    END LOOP;
    END;
    but first I had to create the type NUM_ARRAY like this:
    CREATE TYPE subjectid_tab AS TABLE OF NUMBER INDEX BY binary_integer;
    THANK YOU, GUYS. YOU ARE THE BESTS. ;-)
    Edited by: user12249099 on 08-sep-2011 7:37
    Edited by: user12249099 on 08-sep-2011 7:37

  • Several times I've downloaded albums from iTunes to find that some of the tracks did not get fully downloaded so that the track with skip to the next one. Can someone tell me why this is happening and how I can fix it?

    Several times I've downloaded an album from iTunes to find that not all of the tracks were fully downloaded so that some of the tracks will skip to the next one (instead of finishing the song). Can anyone tell me why this happens and how I can fix it?

    If your country's iTunes Store allows you to redownload purchased tracks, I'd delete your current copies of the tracks and try redownloading fresh copies.
    Otherwise, I'd report the problem to the iTunes Store.
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the items that are not playing properly. If you can't see "Report a Problem" next to the items, click the "Report a problem" button. Now click the "Report a Problem" links next to the items.
    (Not entirely sure what happens after you click that link, but fingers crossed it should be relatively straightforward.)

  • How can I get "IMAQ Line Fit" stable (with the same points)

    How can I get "IMAQ Line Fit" stable (with the same points)
    I my vision applications I use a lot off times "IMAQ Line Fit"
    some times the results are not Stable.
    See vi and word document attached.
    When I take the same points but in a other order (sort)
    then suddenly all points are used.
    In this case I was looking for a edge in vertical direction (Y).
    I found the points but "IMAQ Line Fit" did not function well.
    I tried changing all settings like pixel radius and minimum score and
    also threshold and so on. But no result.
    Then I sorted the points reversed and that worked. See vi.
    I use labview Labview 8.6.0 and IMAQ machine vision.
    Maybe this problem is solved in a newer version.
    Please let me know.
    Thanks
    Attachments:
    TEST-imaq-line-fit-86.vi ‏169 KB
    IMAQ-Fit-Line-Problem-86.doc ‏230 KB

    Thank You for your reaction Hossein,
    This "one application" uses "Line fit" about 20 000 000 times a day.
    about 200 will go wrong. With your setting the the "Line fit" for this occasion will work but others will go wrong.
    A algorithm should be:
    1e Stable, when using the same points and settings the result MUST be the same. How the points are sorted should not matter.
    2e Accuracy
    3e Speed
    4e Testing. Is very difficult but al least close points and the same points and sorting ... should be done
    NI now as made a " IMAQ Line Fit" Problem CAR (Corrective Action request) 298016.
    so in the future there will be a update.
    In the mean while a made a line fit which uses Bisquare option from Linear Fit.vi :
      from C:\Program Files\National Instruments\LabVIEW 8.6\vi.lib\analysis\6fits.llb
    This is a temporary fix because "IMAQ Fit Line VI" is not so stable.
    Because outliers should be rejected only Bisquare does this reasonable.
    This program does NOT USE "Minimum Score" and "Pixel Radius"
    Valid fit = When there are enough points within Outlier_Distance.
    Algorithm steps:
    - Determine if line is more horizontal then vertical, Compare DeltaX with DeltaY
    - If DeltaX <= DeltaY then SWAP X Y and later Swap back
    - Sort Points at on X value
    - First : Bisquare Linear Fit
    - Calculate distances to the found line for all points
    - Inliers: Points within Outlier_distance
    - Outliers: Points outside Outlier_Distance
    - Only use Inlier Points
    - Check again if DeltaX < DeltaY then SWAP X Y later SWAP back again
    - Second : Bisquare Linear Fit only with the Inlier Points
    - Results are from the second fit
    Warning : This Program is Not so accurate and Not so fast
    See attachments it is in labview 8.6
    If some has a improvement please let me know.
    Thanks
    Attachments:
    svi_fit_line_Bsquare_and_draw.vi ‏18 KB
    Fit_Line_Bisquare_Linear.vi ‏40 KB

  • How can I replace an older save file with a new one on game center?

    Greetings,
    I have been trying to change an older game saved file that I have created with my old Ipad with the new one that I have created on my new Ipad, both game files are played under my apple ID but I have no idea how to replace my older one with the new one.
    The new file is superior to the old one so I wish to add the new saved file to my game center.
    The game I am playing is Clash of Clans both file are created on apple products.
    Let me know if there is a sulotion for that case.
    Regards

    Make sure the site folder created by iWeb is named exactly the same as the site folder currently on the server.
    OT

  • How do I make a hands free call with the iphone 4s?

    How do I make a hands free call with the iphone 4s?  I have a bluetooth car device and when I try to talk through it (as I did with my old phone) to call someone it does not work.  so far only hte last person called is redialed.

    That is a carrier-based service. So first you have to make sure your service contract includes that feature.
    It usually also includes Call Hold. So you call the first party, put them on hold, call the second, then reactivate the first. But only if your carrier allows you to.

  • Does anyone know how to connect an older 20" cinema display with the (ADC) adapter end and connect it to a MacBook Pro 17" 2008 model (DVI) ?????

    Does anyone know how to connect an older 20" cinema display with the (ADC) adapter end and connect it to a MacBook Pro 17" 2008 model (DVI) ?????

    I believe you naeed the Apple ADC to DVI adapter.

Maybe you are looking for

  • HT2052 Does anyone have a solution to getting my iPod touch 1st generation to show up in iTunes without having to pay a big service fee for tech support?

    I have an iPod touch 1st generation.  Up until the last update it was recognized in iTunes and now it will not come up in iTunes at all.  Don't feel like I should have to pay $100 every times iTunes updates and there is a problem with it recognizing

  • Personal hotspot not getting router and DNS configured

    My provider for cellular is "bob" (A1) in Austria. I want to make my iPad to provide network access via cellular as a personal hotspot. The network is broadcasted and I can see it at any other device when activating Wi-Fi. When I connect it times out

  • Internal error in FORM/FUNCTION MLCCS_PLANSPLIT_READ

    Hi, While settling a Production Order we are getting the error as 'Internal error in FORM/FUNCTION MLCCS_PLANSPLIT_READ' . I checked the routing . There are no activities for the Production order. Can any body sugest any solution for the same. Thanks

  • Need a Button behavior: go to next chapter

    I have a book with about 20 files in it. Each file is a separate chapter. On my master pages, I need two buttons: one that jumps to the next chapter and one that jumps to the previous chapter. But, those destinations are different for each document i

  • New JSP Tags in WLS 7

              Hi!           Can someone summarize for me additional custom WebLogic JSP tags available in           WLS 7, compared to WLS 6.1 or changes in functionality of existing custom WebLogic           JSP tags from WLS 6.1 to WLS 7.           Tha