Script-Fu Problem with a simple function that renames the selected layer - function

I am writing a simple script to rename the selected layer.
Here is the code:
(script-fu-register
"script-fu-renaming" ;code name
"Renaming Function" ;name
"This is for a question for Stack Overflow" ;description
"Me" ;author
"copyright 2020, Me" ;copyright
"Wednesday 8/Jul/2020" ;date
"" ;?
)
(define (script-fu-renaming)
(gimp-item-set-name (gimp-image-get-active-layer 1) "屈")
)
But when I execute it on the Script-Fu console, through this "(script-fu-renaming 0)", I got the following error: "Error: ( : 32595) Invalid type for argument 1 to gimp-item-set-name".
So my question would be what is the code to do what I explained above without getting errors?

Like most GIMP functions gimp-image-get-active-layer returns a list, so you need to extract the first element using car :
(gimp-item-set-name (car (gimp-image-get-active-layer 1)) "?")

Related

why is this racket code giving me a function call error?

i am working through this online book //htdp.org/2021-11-15/Book/index.html to learn the racket.as i progressed through the book i came across this code - this isnt my code and all it had asked of me was to change the ... with a string which i did - check below - first one is from the site - second one is the one i modified with strings as as specifed
(define current-color ...)
(define next-color
(if (string=? "green" current-color) "yellow" ...))
(define current-color "red")
(define next-color
(if (string=? "green" current-color) "yellow" "amber"))
and when i run it i get this error
(next-color "green")
function call: expected a function after the open parenthesis, but found a variable
am i missing something please help me out
next-color, defined as:
(define next-color
(if (string=? "green" current-color) "yellow" "amber"))
is variable, not function, so you can't call it like this: (next-color "green"). If you want to get its value, just type into REPL:
> next-color

Python/JSON : I want to go to a specific thing when it can't find it in a json file

I'm actually making my discord bot and I wanted to make a command to know plane informations. I made it but know i want to put plane photos depending on the company.
I tried to do that:
if plane_data["data"][f"{flight_companie}"] == "FedEx" or "Ryanair" or "SWISS" or "Air France" or "SWISS" or "British Airways":
plane_photo = plane_data["data"][flight_companie]
else:
plane_photo = plane_data["data"]["unknown"]
Unknown is equal to a url photo that says there is no plane photos.
When i try with UPS it gives me that out:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'UPS Airlines'
Please help me out!!
if plane_data["data"][f"{flight_companie}"] == "FedEx" or "Ryanair"...
will always evaluate to True. This is because a string like "Ryanair" is truthy. Meaning it becomes true when converted to a boolean. So your line is equivialent to
if plane_data["data"][f"{flight_companie}"] == "FedEx" or True or True or True ...
or can not be used in this situation. I would use
if plane_data["data"][f"{flight_companie}"] in ["FedEx","Ryanair","SWISS","Air France","SWISS","British Airways"]:
instead.

Evaluate a string term in prolog

I'm trying to create a prolog program which receives the queries to run as strings (via json) and then print the result (succeed or fails).
:- use_module(library(http/json)).
happy(alice).
happy(albert).
with_albert(alice).
does_alice_dance :- happy(alice),with_albert(alice),
format('When alice is happy and with albert, she dances ~n').
with_alice(albert).
does_albert_dance :- happy(albert),with_alice(albert),
format('When albert is happy and with alice, he dances ~n').
fever(martin).
low_appetite(martin).
sick(X):-fever(X),low_appetite(X).
main(json(Request)) :-
nl,
write(Request),
nl,
member(facts=Facts, Request),
format('Facts : ~w ~n',[Facts]),
atomic_list_concat(Facts, ', ', Atom),
format('Atom : ~w ~n',[Atom]),
atom_to_term(Atom,Term,Bindings),
format('Term : ~w ~n',Term),
write(Bindings).
After executing this query :
main(json([facts=['sick(martin)', 'does_alice_dance',
'does_albert_dance']])).
i had :
[facts=[sick(martin), does_alice_dance, does_albert_dance]]
Facts : [sick(martin),does_alice_dance,does_albert_dance]
Atom : sick(martin), does_alice_dance, does_albert_dance
Term : sick(martin),does_alice_dance,does_albert_dance
[]
true
What i would like to do is to evaluate Term. I tried to make it work using the is/2 and the call predicates but it doesn't seem to work.
using
call(Term)
(i added in the tail of the main), i had this error :
Sandbox restriction!
Could not derive which predicate may be called from
call(C)
main(json([facts=['sick(martin)',does_alice_dance,does_albert_dance]]))
using
Result is Term
(Result is a variable i added to store the result), i had this error :
Arithmetic: `does_albert_dance/0' is not a function
Is there ay solution to evaluate strings expressions in prolog please ?
As #David Tonhofer said in the first comment, The issue was that i'm testing my code on an online editor (which restrict some prolog features like the invocation of the call predicate). So after adding the call predicate to the tail of my program :
main(json(Request)) :-
nl,
write(Request),
nl,
member(facts=Facts, Request),
format('Facts : ~w ~n',[Facts]),
atomic_list_concat(Facts, ', ', Atom),
format('Atom : ~w ~n',[Atom]),
atom_to_term(Atom,Term,Bindings),
format('Term : ~w ~n',Term),
write(Bindings),
call(Term).
and testing it on my local machine. It works fine.

TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U57') dtype('<U57') dtype('<U57')

I am using great-expectation for pipeline testing.
I have One Dataframe batch of type :-
great_expectations.dataset.pandas_dataset.PandasDataset
I want to build dynamic validation expression.
i.e
batch.("columnname","value") in which
validationtype columname and value coming from json file .
JSON structure:-
{
"column_name": "sex",
"validation_type": "expect_column_values_to_be_in_set",
"validation_value": ["MALE","FEMALE"]
},
when i am building this expression getting error message described below .
Code:-
def add_validation(self,batch,validation_list):
for d in validation_list:
expression = "." + d["validation_type"] + "(" + d["column_name"] + "," +
str(d["validation_value"]) + ")"
print(expression)
batch+expression
batch.save_expectation_suite(discard_failed_expectations=False)
return batch
Output:-
print statement output
.expect_column_values_to_be_in_set(sex,['MALE','FEMALE'])
Error:-
TypeError: ufunc 'add' did not contain a loop with signature matching
types dtype('
In great_expectations, the expectation_suite object is designed to capture all of the information necessary to evaluate an expectation. So, in your case, the most natural thing to do would be to translate the source json file you have into the great_expectations expectation suite format.
The best way to do that will depend on where you're getting the original JSON structure from -- you'd ideally want to do the translation as early as possible (maybe even before creating that source JSON?) and keep the expectations in the GE format.
For example, if all of the expectations you have are of the type expect_column_values_to_be_in_set, you could do a direct translation:
expectations = []
for d in validation_list:
expectation_config = {
"expectation_type": d["validation_type"],
"kwargs": {
"column": d["column_name"],
"value_set": d["validation_value"]
}
}
expectation_suite = {
"expectation_suite_name": "my_suite",
"expectations": expectations
}
On the other hand, if you are working with a variety of different expectations, you would also need to make sure that the validation_value in your JSON gets mapped to the right kwargs for the expectation (for example, if you expect_column_values_to_be_between then you actually need to provide min_value and/or max_value).

Latex or HTML summary output table for vglm regression objects (VGAM)

I'm trying to get a latex or html output of the regression results of a VGAM model (in the example bellow it's a generalized ordinal logit). But the packages I know for this purpose do not work with a vglm object.
Here you can see a little toy example with the error messages I'm getting:
library(VGAM)
n <- 1000
x <- rnorm(n)
y <- ordered( rbinom(n, 3, prob=.5) )
ologit <- vglm(y ~ x,
family = cumulative(parallel = F , reverse = TRUE),
model=T)
library(stargazer)
stargazer(ologit)
Error in objects[[i]]$zelig.call : $ operator not defined for this S4 class
library(texreg)
htmlreg(ologit)
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘extract’ for signature ‘"vglm"’
library(memisc)
mtable(ologit)
Error in UseMethod("getSummary") : no applicable method for 'getSummary' applied to an object of class "c('vglm', 'vlm', 'vlmsmall')"
I just had the same problem. My first work around is to run the OLogit Regression with the polr function of the MASS package. The resulting objects are easily visualizable / summarizable by the usual packages (I recommend sjplot 's tab_model function for the table output!)
2nd Option is to craft your own table, which you then turn into a neat HTML object via stargazer.
For this you need to know that s4 objects are not subsettable in the same manner as conventional objects (http://adv-r.had.co.nz/Subsetting.html). The most straight forward solution is to subset the object, i.e. extract the relevant aspects with an # instead of a $ symbol:
sumobject <- summaryvglm(yourvglmobject)
stargazer(sumpbject#coef3, type="html", out = "RegDoc.doc")
A little cumbersome but it did the trick for me. Hope this helps!