I am making a text summarization algorithm for my latest app and I am converting the code from python to java. I am stuck on the last part tough. in python they sort the sentences based on the score of the sentences and reverse it.
Code:
sentences.sort(key=lambda s: sentence_score(s, frequencies), reverse=1)
In java I have the sentences array and the score from the sentences. I need to sort the sentences like this .sort(sentencesScore, descending) but I dont really know how to.
Any help would be much appreciated, thanks
The first thing I can think of is to use list of hashmaps with <integer,string> pairing. The integer would be your score value and the string your sentences. You could then simply order them regarding your integer values.
TobyDrane said:
I am making a text summarization algorithm for my latest app and I am converting the code from python to java. I am stuck on the last part tough. in python they sort the sentences based on the score of the sentences and reverse it.
Code:
sentences.sort(key=lambda s: sentence_score(s, frequencies), reverse=1)
In java I have the sentences array and the score from the sentences. I need to sort the sentences like this .sort(sentencesScore, descending) but I dont really know how to.
Any help would be much appreciated, thanks
Click to expand...
Click to collapse
A quick and simple way to do this would be to implement a Comparator to sort your array. This question on StackOverflow has a quick breakdown of it's usage: http://stackoverflow.com/questions/6224978/android-sort-array
Hope this helps, happy coding!
Related
Hi,
I am trying to create some kind of a viewer that can view files in different formats like:
Text(ASCII), Text(UNICODE),Bin, Hex, Oct.
the last two require dealing with bits, (3bits --> 1 oct), (4bits-->1 hex), so what is the fastest way to do this? I need to boost performance
Thanks
Mohammad
Well, I am not sure about octal, but there is nothing easier or more "user friendly" than hex.
For example:
Code:
CString msg;
BYTE arrayOfByte[3];
msg.Format(_T("0x%02x 0x%02x 0x%02x"), arrayOfByte[0], arrayOfByte[1], arrayOfByte[2]);
MessageBox(msg, _T("Hex string"));
There are several operators in C++ language to deal with bits. For one thing you can use masks and binary operators to determine values of individual bits.
Any programming book will have a whole chapter dedicated to bit operations.
Yes friend,
I know the basics of bitwise operators, I have been programming C++ for more than 5 years, but I just wonder if there is someway that is significantly faster than the usual way
Thanks
Mohammad
Hi everyone
I just felt I had to start thread dedicated to s-k-tools NScriptM (http://www.s-k-tools.com/).
I think that you might have missed this app. It seems to be living in the total eclipse of MortScript (which I also adore of course).
NScriptM is in other words a script interpreter. So what makes it different from Mort? Well, first of all it inherits it's syntax from C rather than Basic. This makes it a bit less intuitive, unless you are used to this family of languages of course
But with little more braces and abbreviations comes a lot more power!
How about,
- Type safety (if you want it)
- Regular expressions
- More features for associate arrays (aka hash tables, dictionaries)
- MUCH faster execution!
- More things left to try out
I am coding an xml parser right now. I started with a Mort version but no matter how I tried I just could not get decent speed (2 secs for a tiny doc). Decided to try NScriptM, translated the script and ... I didn't have time to react before it finished with the parsing PLUS getElementByTagName!
Try it and share your snippets here My xml parser will be ready soon.
Ciao,
Lars
sktools....a must!
...yeah have to joinn you on that.....any newbie or any person who does not have sktools on there phone MUST go and do some research on their site....
mysparkle said:
Hi everyone
I just felt I had to start thread dedicated to s-k-tools NScriptM (http://www.s-k-tools.com/).
I think that you might have missed this app. It seems to be living in the total eclipse of MortScript (which I also adore of course).
NScriptM is in other words a script interpreter. So what makes it different from Mort? Well, first of all it inherits it's syntax from C rather than Basic. This makes it a bit less intuitive, unless you are used to this family of languages of course
But with little more braces and abbreviations comes a lot more power!
How about,
- Type safety (if you want it)
- Regular expressions
- More features for associate arrays (aka hash tables, dictionaries)
- MUCH faster execution!
- More things left to try out
I am coding an xml parser right now. I started with a Mort version but no matter how I tried I just could not get decent speed (2 secs for a tiny doc). Decided to try NScriptM, translated the script and ... I didn't have time to react before it finished with the parsing PLUS getElementByTagName!
Try it and share your snippets here My xml parser will be ready soon.
Ciao,
Lars
Click to expand...
Click to collapse
Sounds great! Seeing as how Sashimi has trouble redrawing the screen after certain operations, I'm glad to see something that is faster. I've got some experience with C/C++ so I'm good.
ralpheboyo said:
...yeah have to joinn you on that.....any newbie or any person who does not have sktools on there phone MUST go and do some research on their site....
Click to expand...
Click to collapse
However, I must agree with ralpheboyo, a link should have been posted pointing to the page where the software could be downloaded. NScriptM is located here: http://s-k-tools.com/index.html?m_util.html. Thank you for pointing us to this great piece of software mysparkle. Now I can finally build a working program for my project.
Managed to accidentally delete the whole NScriptM folder along with all the scripts
Well well... I have been a developer long enough to know that code is always better the second time around so...
Give me some more time and i will make both a JSON and XML-RPC client...
Ciao
Lars
Hello XDA, I'm trying to write (what I believe to be) a simple app; a calculator with storage buttons. I've gotten the basic layout and initialized the core components. Yet, when I add on-click listeners, there's a force quit when testing. Attached is the Java class and xml. I've tried very hard to figure out what it is; I've even tried simply putting a println statement in the on-click listener. It doesn't even do THAT
Also, if there's anything (AT ALL) that you could criticize me on in terms of code organization, standards, etc. PLEASE let me know. I'm a newbie, and it's better to kick bad coding habits before they grow strong!
Thanks in advance, guys. I know it's annoying to debug others code, especially beginners, but I don't think it'll take much time at all, and I'd like to think I'm a relatively organized beginner
So I found out what it was; EditText doesn't accept ints or doubles as parameters. There's got to be an easier way of doing this, though. Is there any calculator-window-type objects that will store ints and/or (preferrably or) doubles? It's doable, but highly annoying to cast everything to a string and then parse it back to a numerical data type to perform operations on it.
Hi,
I am new to the Android development scene and I need to pull off a math game project in less then a week. I am using Eclipse to do this, but is there any other easier way such as Visual basic GUI way that you can pull off 100% raw code from it?
Can someone help me through this? . I need basic knowledge on text label, input box, button, perform math operation , if statement, loops, and method. If anyone can quickly guide me through this would be great.
Basically I am programming a math game with subtraction and division. I need to have difficulty mode easy medium hard which is basically randomized numbers in bigger range. Then there is level from 1-4 which is increasement of number of questions. And there are lives also.
Thanks In advance if someone can help me
This sounds like a class
Have you tried to even do the layout in eclipse yet? That is a pretty simple step that shouldn't take longer than 15 minutes.
joshtrader said:
Hi,
I am new to the Android development scene and I need to pull off a math game project in less then a week. I am using Eclipse to do this, but is there any other easier way such as Visual basic GUI way that you can pull off 100% raw code from it?
Can someone help me through this? . I need basic knowledge on text label, input box, button, perform math operation , if statement, loops, and method. If anyone can quickly guide me through this would be great.
Basically I am programming a math game with subtraction and division. I need to have difficulty mode easy medium hard which is basically randomized numbers in bigger range. Then there is level from 1-4 which is increasement of number of questions. And there are lives also.
Thanks In advance if someone can help me
Click to expand...
Click to collapse
It will be really simple to make.. I can code it if you want.. but I am really bad in making the GUI.
zalez said:
This sounds like a class
Have you tried to even do the layout in eclipse yet? That is a pretty simple step that shouldn't take longer than 15 minutes.
Click to expand...
Click to collapse
yes i did try to fiddle with the gui layout in eclipse, i was able to make a text box, input box and button that display a message.
prototype-U said:
It will be really simple to make.. I can code it if you want.. but I am really bad in making the GUI.
Click to expand...
Click to collapse
Thanks for offering to help but i would like to understand the fundemental of coding in this android field. I have indeed done Java before, and i made the exact math game that i am attempting to do on this project, my java game was consisting with loops/if/while statements (for # of questions), randomizing numbers, menu options. I do know that android uses java language but when i went through the official guide on the developer website, it seems a bit too challenging to follow.
it would be great if someone could guide me with an example statements of using methods, loops such as if and while/for how to interpret info from input box and or interpret from user click button and such.
If it would be any help, i can post my original java math game
Hello,
I've recently taken to learning Java in an effort to create a game I have an idea for. I'm following this tutorial/guide at kilobolt . com and I've run into a little problem trying to understand something. I'm familiar with a few programming languages (C++, Python, VB) and I've been running through the Java basics just to get to grips with the syntax.
Before you start blasting me I did have a quick search. Couldn't find what I was looking for:
In regards to class inheritance and implementation, lets say I want to design a few different characters for a game that all share some generic aspects. As I learnt about interfaces first this seemed to be a simple way for new characters to acquire these shared aspects, but then I learnt about superclasses, and I'm at a bit of a loss as to which would ultimately benefit my application more as a whole. Of course I want it to run efficiently as possible, so would anyone have any hints or recommendations for me? forgive me if there's something i'm missing.
thanks in advance.
@Lacanau
You can take inheritance as follows supposingly your game chaters have some common attributes so you can have a class
GameCharecter
with broader specs which are commom to all
class GameCharecter{
.............
assign common attributes like
hasEyes
hasLegs
bla bla.........
}
now narrowing it to inheritance
Now lets say you are to have a Charecter named CR7 that will share the attributes common to other charecters like hasLegs.....
class CR7 extends GameCharecter
{
.....
extending the GameCharecter class(superclass) will assing this charecter with basic attributes common to all as declared in (super)GameCharecter
here in this class you will provide attributes specific to this charecter
like its cothing etc.
}
now coming to your app as you said you need to share attributes so that is best achieved by Inheritance aka extending Classes
as far as implementation is considered it is best suited if you want your Classes to share common behaviour
Sent from my GT-S5302 using Tapatalk 2