Does anyone know of a good way to calculate the "semantic distance" between two words?
Immediately an algorithm that counts the steps between words in a thesaurus springs to mind.
For this example data:
Index, State, Food
1, CA, Hamburger
2, NY, Lettuce
3, CA, Cheese
4, NY, Lettuce
5, NY, Cheese
6, AR, Cheese
I would like to group by State and show the most common food for each state. So the result for the example should be:
State, Popular Food
CA, Hamburger
NY, Lettuce
AR, Cheese
The problem is I can't find an aggregation that would return the most common string.
There is the 'mode' function but it only works on integers.
Am I missing Something?
Thanks!
Related to my previous question (found here), I want to be able to implement the answers given with a 2 dimensional array, instead of one dimensional.
Reference Array
row[1][0]: 13, row[1][1]: Sony
row[0][0]: 19, row[0][1]: Canon
row[2][0]: 25, row[2][1]: HP
Search String: Sony's Cyber-shot DSC-S600
End Result: 13
I have attempted to implement a producer/consumer pattern in c#. I have a consumer thread that monitors a shared queue, and a producer thread that places items onto the shared queue. The producer thread is subscribed to receive data...that is, it has an event handler, and just sits around and waits for an OnData event to fire (the data is being sent from a 3rd party api). When it gets the data, it sticks it on the queue so the consumer can handle it.
When the OnData event does fire in the producer, I had expected it to be handled by my producer thread. But that doesn't seem to be what is happening. The OnData event seems as if it's being handled on a new thread instead! Is this how .net always works...events are handled on their own thread? Can I control what thread will handle events when they're raised? What if hundreds of events are raised near-simultaneously...would each have its own thread?
I'm fairly new to OOP in PHP, I've made a couple of basic scripts but nothing impressive. All I've really taken from it is that it would probably be easier just make a collection of functions and include them.
The structure of classes seems to just confuse what was otherwise a simple process. And in collating everything into a class it doesn't really add any functionality.
So I'm clearly missing something. Could someone explain what functionality is added by creating classes
When I call the function, the dialog does work.
If I move the dialog construction into the showtimes_list function, everything works fine.
I thought that variables declared outside a function were global in context?
var dialog_list = $("<div></div>").dialog({
autoOpen: false,
modal: true,
height: 300, width: 720,
});
function showtimes_list(sid){
dialog_list.html("");
$.get("ajax_showtimes.php?sid="+sid, function(data){
dialog_list.html(data);
}
);
dialog_list.dialog("open");
}
Hi,
I am trying to add a dll that contains some custom 3rd party conrtols and some in house user controls and am getting the following error -
"The Assembly "MyASsembly.dll" could not be loaded. Check that any dependencies the file requires are installed"
I am using Visual Studio 2003 and the 3rd part controls are C1.
Does anyone know what is wrong?
Thanks
I've seen lots of MEF code for plugging into custom apps, but I am yet to find out how to write a plugin for VS2010 using MEF. I was under the impression that the new IDE supported this.
Does anyone have any links, tips, etc?
Whenever I add paddingRight to a column in the flex grid, it adds the padding to the header as well.
Is anyone familiar with how I can add paddingRight just to the column and not to the header? Below is the column code where I was specifying the padding.
<mx:DataGridColumn width="60" headerText="Type" dataField="Grade" headerStyleName="headerLeft" textAlign="left" draggable="false" resizable="false" headerRenderer="GridHeaderRenderer" paddingRight="5"/>
I have a large class, which I have divided into several different class extension files for readability.
@protocol MyProtocol
@required
-(void)required;
@end
@interface MyClass : NSObject <MyProtocol>
@end
@interface MyClass (RequiredExtension)
-(void)required;
@end
Is there a better way to do this, without the compiler warning?
warning: class 'MyClass' does not fully implement the 'MyProtocol' protocol
My SQL Compact database is very simple, with just three tables and a single index on one of the tables (the table with 200k rows; the other two have less than a hundred each).
The first time the .sdf file is used by my Compact Framework application on the target Windows Mobile device, the system hangs for well over a minute while "something" is done to the database: when deployed, the DB is 17 megabytes, and after this first usage, it balloons to 24 megs.
All subsequent usage is pretty fast, so I'm assuming there's some sort of initialization / index building going on during this first usage. I'd rather not subject the user to this delay, so I'm wondering what this initialization process is and whether it can be performed before deployment.
For now, I've copied the "initialized" database back to my desktop for use in the setup project, but I'd really like to have a better answer / solution. I've tried "full compact / repair" in the VS Database Properties dialog, but this made no difference. Any ideas?
For the record, I should add that the database is only read from by the device application -- no modifications are made by that code.
I'm working from a question I posted earlier (here), and trying to convert the answer to a sub so I can use it multiple times. Not sure that it's done right though. Can anyone provide a better or cleaner sub?
sub search_for_key
{
my ($args) = @_;
foreach $row(@{$args->{search_ary}}){
print "@$row[0] : @$row[1]\n";
}
my $thiskey = NULL;
my @result = map { $args->{search_ary}[$_][0] } # Get the 0th column...
grep { @$args->{search_in} =~ /$args->{search_ary}[$_][1]/ } # ... of rows where the
0 .. $#array; # first row matches
$thiskey = @result;
print "\nReturning: " . $thiskey . "\n";
return $thiskey;
}
search_for_key({
'search_ary' => $ref_cam_make,
'search_in' => 'Canon EOS Rebel XSi'
});
One of our vendors provides a web service API to allow their customers to validate data in a database. As part of their SDK, they provide a WSDL (Web Service Definition Language) file that, according to their documentation, can "be read by software applications and application development tools. An application tool such as Microsoft's Visual Studio can import a WSDL document and automatically generate software classes that access the Web Services the WSDL defines."
I'm currently using Visual Studio 2005. What do I need to do to get Visual Studio to do the magic code generation for me?
I've got a site that provides blog-friendly widgets via JavaScript. These work fine in most circumstances, including self-hosted Wordpress blogs. With blogs hosted at Wordpress.com, however, JavaScript isn't allowed in sidebar text modules. Has anyone seen a workaround for this limitation?
I'm pretty new to C++ and was looking for a good way to pull the data out of this line.
A sample line that I might need to tokenise is
f 11/65/11 16/70/16 17/69/17
I have a tokenisation method that splits strings into a vector as delimited by a string which may be useful
static void Tokenise(const string& str, vector<string>& tokens, const string& delimiters = " ")
The only way I can think of doing it is to tokenise with " " as a delimiter, remove the first item from the resulting vector, then tokenise each part by itself. Is there a good way to do this all in one?
I have a method Get on a type MyType1 accepting a Func<MyType2, bool> as a parameter.
An example of its use:
mytype1Instance.Get(x => x.Guid == guid));
I would like create a stub implementation of the method Get that examines the incoming lambda expression and determines what the value of guid is. Clearly the lambda could be "anything", but I'm happy for the stub to make an assumption about the lambda, that it is trying to match on the Guid property.
How can I do this? I suspect it involves the use of the built-in Expression type?
What would you say is the best book to buy to understand exactly how programming works under the hood in order to increase performance? I've coded in assembly at university, I studied computer architecture and I obviously did high level programming, but what I really dont understand is things like:
-what is happening when I perform a cast
-whats the difference in performance if I declare something global as opposed to local?
-How does the memory layout for an ArrayList compare with a Vector or LinkedList?
-Whats the overhead with pointers?
-Are locks more efficient than using synchronized?
-Would creating my own array using int[] be faster than using ArrayList
-Advantages/disadvantages of declaring a variable volatile
I have got a copy of Java Performance Tuning but it doesnt go down very low and it contains rather obvious things like suggesting a hashmap instead of using an ArrayList as you can map the keys to memory addresses etc. I want something a bit more Computer Sciencey, linking the programming language to what happens with the assembler/hardware.
The reason im asking is that I have an interview coming up for a job in High Frequency Trading and everything has to be as efficient as possible, yet I cant remember every single possible efficiency saving so i'd just like to learn the fundamentals.
Thanks in advance
CALORIES = \
{ 'Beef' : 200, \
'Chicken' : 140, \
}
class Food():
__slots__ = (
'cal' # Calories
)
def mkFood( name ):
"""Create and return a newly initialized Food item"""
result = Food()
result.cal = calorie in dict(CALORIES[1])
return result
Is that a proper way to the value of the target item in Calories? Like getting 200, 140, such like that.
result.cal = calorie in dict(CALORIES[1])
I am looking to split up multiple lines of text to single them out, for example:
Url/Host:ftp://server.com/1
Login:Admin1
Password:Password1
Url/Host:ftp://server.com/2
Login:Admin2
Password:Password2
Url/Host:ftp://server.com/3
Login:Admin3
Password:Password3
How can I split each section into a different textbox, so that section one would be put into TextBox1.Text on its own:
Url/Host:ftp://server.com/1
Login:Admin1
Password:Password1
Thanks in advance :)!
I created a Linq-to-SQL DBML for the first time. I dragged and dropped all my tables over to the designer. The tables all appear in the designer.cs file. In Global.asax, I also have model.RegisterContext() with the ScaffoldAllTables = true option. The routes are also setup.
I can pull up the Scaffolding page, but there's at least one table that is missing that I'm trying to get to show up. This missing table has a relationship with a child table that references it. The child table appears. When viewing data for the child table, the column that references the missing/parent table shows the numeric PK int value, rather than showing the "name". So instead of showing "Cars" it shows 1, and instead of showing "Planes" it shows 2, etc.
There's another table in the DB that has the same type of structure as the missing table, and it is correctly appearing in the scaffolded tables.
For this missing table, I've tried explicitly adding the ScaffoldTable attribute to no avail.
Does anyone know what would cause a table like this to not appear in the list Scaffolded tables? Thanks very much.
Hi, im trying to add a "rating" system to an existing form (i.e 1 star, 2 Star or poor, average,good,excellent etc).
Does anyone know of a way to achieve this that is aesthetically pleasing with good UX either in .Net or a free 3rd party control?
Thanks
In my time of digging around Java APIs I have come across both impl and internal packages. Up until now I never really thought about the difference - as with all enterprisey Java apps, I figured they just meant that "actual implementation in here; you (API user) should be really using the interface. Go away."
A little bit of digging around Stack Overflow seems to suggest that the internal package at least can have some security placed around it.
So, what is the difference? I don't think it is a matter of taste because I have seen APIs with both.
According to the standard, a conversion function has a function-id operator conversion-type-id, which would look like, say, operator char(&)[4] I believe. But I cannot figure out where to put the function parameter list. gcc does not accept either of operator char(&())[4] or operator char(&)[4]() or anything I can think of.
Now, gcc seems to accept (&operator char ())[4] but clang does not, and I am inclined to not either, since it does not seem to fit the grammar as I understand it.
I do not want to use a typedef because I want to avoid polluting the namespace with it.
Is it possible to have a textarea with max length in html so that the max length will not be exceeded even when pasting text? I have yet to see anyone implement this correctly, being able to handle the paste event when right-clicking and selecting paste.