#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Smile Reading repeated exactly 3 times from text files?


    hi friends,
    i have requirments like this
    in a directory some txt files in file management so i need to find the exactly 3 times repeated word and display the txt file name and word name to output???
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    This code in executable Iverson notation solves the problem for a single file:
    Code:
       (3=>@:{.@:|:)Filter(#;{.)/.~;:(e.&(LF,'''')`(,:&' '))}1!:1<'/tmp/p.py'
    ┌─┬──────┐
    │3│import│
    ├─┼──────┤
    │3│read  │
    ├─┼──────┤
    │3│I     │
    ├─┼──────┤
    │3│set   │
    ├─┼──────┤
    │3│char  │
    ├─┼──────┤
    │3│key   │
    ├─┼──────┤
    │3│-     │
    ├─┼──────┤
    │3│end   │
    └─┴──────┘
       Filter
    (#~`)(`:6)
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    82
    Originally Posted by b49P23TIvg
    This code in executable Iverson notation solves the problem for a single file:
    Code:
       (3=>@:{.@:|:)Filter(#;{.)/.~;:(e.&(LF,'''')`(,:&' '))}1!:1<'/tmp/p.py'
    ┌─┬──────┐
    │3│import│
    ├─┼──────┤
    │3│read  │
    ├─┼──────┤
    │3│I     │
    ├─┼──────┤
    │3│set   │
    ├─┼──────┤
    │3│char  │
    ├─┼──────┤
    │3│key   │
    ├─┼──────┤
    │3│-     │
    ├─┼──────┤
    │3│end   │
    └─┴──────┘
       Filter
    (#~`)(`:6)

    I tried running your example using JConsole and it crashed with the following error message:

    |Value error: Filter
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    The definition of Filter appears at the end of that post.---yes, I appended it as an after thought, but you need it up front.

    Code:
       Filter=: (#~`)(`:6)
       (3=>@:{.@:|:)Filter(#;{.)/.~;:(e.&(LF,'''')`(,:&' '))}1!:1<'/tmp/p.py'
    also, '/tmp/p.py' is a string containing the name of an existing file on my computer system. You'd need to replace it with a reasonable alternative on your system. I think you made that substitution otherwise you'd have gotten a different error.

    If you're interested, I'll make an effort to explain the sentence.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    82
    Originally Posted by b49P23TIvg
    The definition of Filter appears at the end of that post.---yes, I appended it as an after thought, but you need it up front.

    Code:
       Filter=: (#~`)(`:6)
       (3=>@:{.@:|:)Filter(#;{.)/.~;:(e.&(LF,'''')`(,:&' '))}1!:1<'/tmp/p.py'
    also, '/tmp/p.py' is a string containing the name of an existing file on my computer system. You'd need to replace it with a reasonable alternative on your system. I think you made that substitution otherwise you'd have gotten a different error.

    If you're interested, I'll make an effort to explain the sentence.
    It works somewhat. That is, there are no more syntax errors but it chokes on input files. For example, if I feed the following ASCII text file into the app, it will just hang.

    forty three ninety
    ten
    four
    six
    three
    nine
    three
    two
    five seven nine twelve
    two eighty
    fourteen
    thirty forty fifty sixty seventy eighty
    nine nine nine nine nine nine nine nine nine nine nine nine


  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    82
    in a directory some txt files in file management so i need to find the exactly 3 times repeated word and display the txt file name and word name to output???
    One possible solution is to use a c++ Vector Class template . You would use two vectors, one designated as a string and the other designated as an int. The string vector would hold all the unique words and the int vector would hold the unique word count. Actual processing would require that you strip out all punctuation and then convert everything to lower case for comparision purposes.
  12. #7
  13. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    I don't understand. Here I've removed the Filter adverb

    (replaced its functionality with modified sentence) and it works with j6 and j7. Your file is /tmp/a
    Code:
    $ /usr/local/j64-701/bin/jconsole
       JVERSION
    Engine: j701/2011-01-10/11:25
    Library: 7.01.076
    Platform: Linux 64
    Installer: j701a_linux64.sh
    InstallPath: /usr/local/j64-701
       
    
       
       (#~3=>@:{.@:|:)(#;{.)/.~;:(e.&(LF,'''')`(,:&' '))}1!:1<'/tmp/a'
    ┌─┬─────┐
    │3│three│
    └─┴─────┘
    
    
    
    $ /usr/local/j64-602/bin/jconsole 
       JVERSION
    Installer: j602a_linux64.sh
    Engine: j602/2008-03-03/16:45
    Library: 6.02.055
    
       
    
       (#~3=>@:{.@:|:)(#;{.)/.~;:(e.&(LF,'''')`(,:&' '))}1!:1<'/tmp/a'
    ┌─┬─────┐
    │3│three│
    └─┴─────┘
    [code]Code tags[/code] are essential for python code and Makefiles!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    82
    I think my initial problem was trying to install/run the application on Windows 7 64 bit. So, I installed the app and tried it on a Ubuntu 64 bit box and it it ran successfully.

    I'm just not sure I'd want to be the OP and try to decipher that cryptic coding.
  16. #9
  17. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    The OP showed no effort nor gave a reason for choosing a particular language. j is a gem even though it can look like line noise.

    I could have written definitions to make a j sentence something like:
    Code:
    show 3 filter count each word ' ' replace ('''',LF) read 'filename'
    The lower level definitions would still look like spurts of line noise
    read=: 1!:1@<

    How do you make an identity matrix in your favorite language? I'll bet it takes more than 3 characters + argument length.
    Code:
       =i.5
    1 0 0 0 0
    0 1 0 0 0
    0 0 1 0 0
    0 0 0 1 0
    0 0 0 0 1
    The = and i. verbs weren't designed "to construct identity matrices." They embody useful data processing ideas alone.
    Code:
       i. 5
    0 1 2 3 4
    
       i. 2 3 4
     0  1  2  3
     4  5  6  7
     8  9 10 11
    
    12 13 14 15
    16 17 18 19
    20 21 22 23
    Last edited by b49P23TIvg; November 21st, 2012 at 09:39 AM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    82
    j is a gem even though it can look like line noise.
    I was a little skeptical of the code that looks like nothing more than complete gibberish and a programming language that I never heard of (J). I honestly thought that the code would never work. So, I had to test it. Much to my total amazement it did work!

    I'm not even going to try to decipher that code gibberish It'll probably put me in a mental asylum.
  20. #11
  21. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    J is Ken's final dialect of APL.
    Awards for Ken Iverson:
    Originally Posted by wikipedia
    Awards

    IBM Fellow (IBM) (1970)
    Harry H. Goode Memorial Award (IEEE Computer Society) (1975)
    Turing Award (Association for Computing Machinery) (1979)
    Computer Pioneer Award [Charter recipient] (IEEE Computer Society) (1982)
    Honorary doctorate, York University, Toronto, 1998
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo