Why am I not getting an output? - wolfram-mathematica

I'm trying to filter (comments) which is survey response from CSV file so all text.
I did
classify[“sentiment”,comments]
And
Counts[classify[“sentiment”,comments]]
Which works fine
So now I want to filter my data to only show negative comments so I'm trying…
Select[comments,classify[“sentiment”,comments]==Negative]
But I'm not getting any output

comments = {
"I love this movie",
"Of cabbages and kings",
"My phone broke again"};
Select[comments, Classify["Sentiment", #] == "Negative" &]
{"My phone broke again"}
Or calling Classify once on the list of comments, probably faster.
sentiments = Classify["Sentiment", comments];
Extract[comments, Position[sentiments, "Negative"]]
{"My phone broke again"}

Related

Exclude multi-word keywords from Twitter Search API

I have a list of keywords to be excluded from search here
KEYWORDS = %w[
covid corona subway railway travel plane brazil ]
exclude = Twitter::KEYWORDS.split(",").join(" -")
and this is how my search query looks like
json_response = #client.search("(javascript) -#{exclude}", lang: "en", result_type: "recent", tweet_mode: "extended", count: 100)
How can I pass multi-word keywords here to be excluded, for example keywords like "off the hand" or "game plan"?
Adding them along with the other keywords doesn't work as expected.
In case anyone comes back looking for the same problem, this is how I solved it:
#client.search("(javascript) -#{exclude} -\"off the hand\" -\"game plan\", lang: "en", result_type: "recent", tweet_mode: "extended", count: 100)
So, basically by using escape characters which allowed me to pass multi-word keywords as an exact string.

Bot Framework Rendering Choices Changes Format

I've just tested a dialog with a list of choices that seem to render differently and I can't find any information on why this would be happening.
Given this list of choices:
Choices = ChoiceFactory.ToChoices(new List<string>
{
"No",
"Yes - xxxxxxxxxxxxxxxxx",
"Yes - xxxxxxxxxxxxxxxxx",
"Yes - xxxxxxxxxxxxxxxxx",
"Yes - xxxxxxxxxxxxxxxxx"
})
It renders like this:
Whereas this list:
Choices = ChoiceFactory.ToChoices(new List<string>
{
"No",
"Yes 2",
"Yes - 3",
"Yes - 4",
"Yes - 5"
})
It renders how I want it too:
I've got other instances where I have a long list of buttons that scroll so I'm very confused why the first list above rendered like a list.
How can I force it to render like the second example?
This behavior has to do with the size of each choice and the amount of choices. When the choices themselves are small (ex: "Yes 2"), then they are able to show as the button type (how you want it to look). When they are displayed in this fashion, and there are many choices; then it will scroll off the screen (as you have seen).
When the choices (any one choice) becomes longer (ex: "Yes - xxxxxxxxxxxxxxxxx") then they get put into the list format. I don't believe there is a way to override this, but I will take a look. If not; the only option is to try and keep your choices small in size.
Additionally; each channel handles rendering/displaying in it's own fashion. For example; if i create many (~20) choices of the small variety; then they will show as the scroll-able "buttons" in web chat, where in Skype they will show as a list.
Because of the strange relationship between Choice and his CardAction, You can shorten the value, but leave the title long, so you'll see cards with long text.
var values = new Dictionary<string, string>
{
{"1", "No"},
{"2", "Yes - xxxxxxxxxxxxxxxxx"},
{"3", "Yes - xxxxxxxxxxxxxxxxx"},
{"4", "Yes - xxxxxxxxxxxxxxxxx"},
{"5", "Yes - xxxxxxxxxxxxxxxxx"}
};
Choices = values.Select(v =>
new Choice(v.Key)
{
Action = new CardAction(title: v.Value, value: v.Key)
})
.ToList()
The key point is to put a short value in Value and a desired value in Title.
The rest of the CardAction settings can be found in this answer.

build app which scans barcodes and sends info to google sheet

Total newbie here but I have a question. We are trying to simplify a second hand book sale and want to build an app which allows parents to scan the barcode of books they want to sell then send this barcode, along with their name and email address (plus maybe a few other questions) to a Google Sheet.
A) is it possible to do this.
B) Any pointers to get started?
EDIT: This is for python code
a) Yes, this is very possible
b)
You are going to need a bar-code scanner that can be connected to a computer and will then, somehow, have to enable this to input into python variables.
In terms of adding to google sheets, it is very possible to do this via Googles current API - if this sounds like jumble, there are plenty of guides at there for doing this in various 'easy' ways.
Here is some basic code to help you get started: (Haven't had the time to test it, and apologies if it is not relevant as I do not know how good you are at python.)
import time
class barcode:
def init(self):
self.code = int()
def getBarcode(self):
print("Insert code to get barcode here. Assign barcode to variable: self.barcode")
if self.barcode != None or self.barcode != "":
return self.barcode()
else:
return False
def getDetails(self):
name = input("Enter your full name: ")
email = input("Enter your email address: ")
return [name, email]
def sendInfo(self, barcode, details):
name = details[0]
email = details[1]
barcode = self.barcode
print("ENTER CODE HERE TO SUBMIT TO GOOGLE SHEETS")
def main(self):
while True:
time.sleep(1)
barcode = self.getBarcode()
if barcode != False:
details = self.getDetails()
self.sendInfo(barcode, details)
If you need more help, or are worse at python than I expect, feel free to comment below.
Extra:
- Haven't had the chance to check it out or check its full relevance however this may help you: https://gist.github.com/JoachimL/1629f701fdb38427091710fc0caef67d

get value from text_field without submitting?

What I need- some kind of way to grab the number entered into the form in order to check it against previous records PRIOR to updating, so that if a validation error occurs, the user can be prompted to confirm before the form is submitted. Params would work, but are only returned after the form is posted- so no help. Is there an ajax call that I can pass into a ruby variable? Or perhaps some kind of ruby code that will read the input in the text box without submitting or linking?
What I'm doing- I'm trying to set up a 'manual validation' because I don't want the validation to 'prevent' from saving. Instead, it should be more like a confirmation.
If you care for context, Here's the run-down- I have a client that pays monthly deposits. We confirm these deposits over the phone through a third party. Naturally, in order to get the most accurate data as possible, we have to account for human error and other factors. A deposit this month should never be less than a deposit last month- but deposits can be "moved" from one account to another, which would make it seem like it was less. I have a form that new data is input on, and I want it to check against previous records to see if the deposit is more or less than reported previously. If less, it should ask for confirmation- an "are you sure?" kind of thing.
The code is old & outdated, should be changed from the ground up, but would take months when I have days to do this. I'm just looking for a patch.
What I have so far- note that cur_deposit is this months and rec_deposit is last months.
<%
arr1 = []
arr2 = []
is_less = false
r = #recent_inquiries.last
r.inquiry_deposits.order(:id).each do |t|
arr1 << t.cur_deposit.to_f
arr1 << t.rec_deposit.to_f
end
#inquiry.inquiry_deposits.order(:id).each do |td|
#============THIS is the part that needs help
arr2 << params["cur_deposit_text_box"]
arr2 << params["rec_deposit_text_box"]
end
i = 0
while i < (arr1.size - 1)
comp_arr1 = []
comp_arr2 = []
comp_arr1 << arr1[i]
comp_arr1 << arr1[i + 1]
comp_arr2 << arr2[i]
comp_arr2 << arr2[i + 1]
if Inquiry.compare_deposits(comp_arr1, comp_arr2) != nil then is_less = true end
i = i + 2
end
if is_less
strConf = "A deposit from last month is greater than the same deposit this month, which should not happen. Are you sure?"
end
%>
<%= submit_tag "Save Inquiry", :onclick=>"$('#submit_form').val('Save Inquiry summary');", :class => 'tgButton3', :id => 'save_inquiry_button_bottom', :confirm => strConf %>
When I get this code working, I will stash all the functioning code into a model- I just have it in the view for testing. It is safe to assume that all the 'custom methods' this script calls to are functioning. If you need code from them, I'll happily share it.
Rails version 3.0.20
Can you use jQuery on your website? (if not it is doable in plain javascript)
$('#id-of-your-field').change(function(e){
//do here your client side logic if any needed
var yourfirstvalue = $(e.target).val();
//now take the value and send it to server (your ruby stuff)
$.ajax({
url: yourURL + "/" + yourfirstvalue,
success: function(data){
//this data can be sent as JSON in structure which suits the best to you
//so you can use it to populate your second dropdown
var values = JSON.parse(data);
//use your values
}
});
});
Google "combo box example" it might help you.
In order to close this question out, and in case anybody else is wondering, I will answer my own question. This is what I've found out.
Because of the nature of the relationship between client & server, there is really no way to get the value of the text input, store it in a ruby variable, and check it against another ruby variable. Ruby script only runs once and then is rendered, so while ajax may be able to continually run in the background and gather inputs, etc, the integration with ruby falls short when talking client-side only interaction. (Correct me if I'm wrong- after all, I posted the question to get everybody's input!)
The fix: I created a switch using hidden tags. When the form loads, the hidden tag is blank. After submitting the form, the update action checks the params of the newly entered data against the numbers from last month. If the conditions check out, it saves. If not, it re-loads the page with a message. If the message is confirmed, an ajax command changes the hidden tag to "true" which bypasses the comparison once it hits the update action again. Otherwise, the data is not saved. Problem solved!
I'm making this a community wiki answer in case anybody would like to add their two cents.

Clear input field and enter new info using Watir? (Ruby, Watir)

Pretty positive you have to use .clear, or maybe not as it doesn't seem to be working for me, maybe i'm just implementing it wrong I'm unsure.
Example:
browser.div(:id => "formLib1").clear.type("input", "hi")
Can anyone tell me how to simply clear a field then enter in a new string?
Assuming we are talking about a text field (ie you are not trying to clear/input a div tag), the .set() and .value= methods automatically clear the text field before inputting the value.
So one of the following would work:
browser.text_field(:id, 'yourid').set('hi')
browser.text_field(:id, 'yourid').value = 'hi'
Note that it is usually preferred to use .set since .value= does not fire events.
I had a similar issue, and, for some reason, .set() and .value= were not available/working for the element.
The element was a Watir::Input:
browser.input(:id => "formLib1").to_subtype.clear
after clearing the field I was able to enter text.
browser.input(:id => "formLib1").send_keys "hi"
I had a similar issue, and, for some reason, .set() and .value= were not available for the element.
The element was a Watir::HTMLElement:
[2] pry(#<Object>)> field.class
=> Watir::HTMLElement
field.methods.grep /^(set|clear)$/
=> []
I resorted to sending the backspace key until the value of the field was "":
count = 0
while field.value != "" && count < 50
field.send_keys(:backspace)
count += 1
end
field.send_keys "hi"

Resources