openedge 12.2 win64 tty
I have a string of comma separated items that the user fills in manually. Elements have a certain structure, and the chk_store method checks each element for correctness of filling and returns the position of the beginning of the first incorrectly filled element. I want that at the on leave event, if there is an incorrectly filled element in the line, then the cursor will move to the position of the beginning of this element. The problem is that the cursor-offset is not set to the position I need when executing the code below.
ON LEAVE OF cfrm-store IN FRAME fmnu
DO:
DO ON ERROR UNDO, RETURN NO-APPLY:
ASSIGN cfrm-store.
icfs = chk_store(cfrm-store).
IF icfs = 0 THEN
LEAVE.
SELF:CURSOR-OFFSET = icfs.
RETURN NO-APPLY.
END.
END.
edit 1.
on leave doesn't work in the console, at least with this syntax, but it works fine in prowin.
def var c as c no-undo init '1234567890' FORMAT 'x(20)'
.
DEF VAR d AS c NO-UNDO INIT '1234567890' FORMAT 'x(20)' .
def button bok auto-go.
def frame f
skip(1)
c
SKIP(1)
d
skip(1)
bok
with view-as dialog-box side-labels.
on leave of c,d in frame f
do:
assign c d.
IF length(SELF:SCREEN-VALUE) <= 10 THEN
DO:
SELF:CURSOR-OFFSET = length(SELF:SCREEN-VALUE) + 1.
RETURN NO-APPLY.
END.
end.
display c d with frame f.
enable all with frame f.
wait-for go of frame f.
I assume that your chk_store function returns the position of the first incorrect element in the list. But to set the cursor position, you need the position of the first incorrect element in the string.
See the example below :
DEFINE VARIABLE list AS CHARACTER NO-UNDO.
DEFINE VARIABLE icfs AS INTEGER NO-UNDO.
DEFINE VARIABLE pos AS INTEGER NO-UNDO.
list = "ok,ok,ok,ok,nok,ok,ok".
icfs = LOOKUP("nok",list). /* = 5 : the position in the list */
pos = INDEX(list, ENTRY(icfs,list)). /* = 13 : the position in the string */
Related
I am having a 1-word document that I want to transform to its bag-of-words representation:
so doc is ['party'] and id2word.doc2bow(doc) is [(229, 1)] which means the word is known.
However, if I call get_document_topics() with doc_bow, the result is an empty list:
id2word = lda.id2word
# ..
doc_bow = id2word.doc2bow(doc)
t = lda.get_document_topics(doc_bow)
try:
label, prob = sorted(t, key=lambda x: -x[1])[0]
except Exception as e:
print('Error!')
raise e
The only possible explanation I'd have here is that this document (the single word) cannot be assigned to any topic. Is this the reason why I am seeing this?
Here is how I solved this issue:
in the file gensim/models/ldamodel.py you need to edit value of epsilon to a larger value.
DTYPE_TO_EPS = {
np.float16: 1e-5,
np.float32: 1e-35, #line to change
np.float64: 1e-100,
}
also, make sure to set the minimum_probability parameter of get_document_topics to a very small value.
I am trying to return a 4D array of image data from a function call in MATLAB. I'm not very advanced in MATLAB and I don't know what type of data I have to return from the function. Here is my function:
function classimg = loadImages(classdir,ext)
% create array of all images in directory
neg = dir([classdir ext]);
% get size of array (to loop through images)
numFileNeg = max(size(neg));
% create a 4D array to store our images
classimg = zeros(51,51,3,numFileNeg);
% loop through directory
for i=1:numFileNeg
classimg(:,:,:,i) = imread([myDir neg(i).name]);
end
end
Here is the function call:
negativeImgs = loadImages("C:\Users\example\Documents\TrainingImages\negatives\","*.jpg");
I cannot find any online documentation for the return type? Does anyone know what this would be? classimg is populated correctly so the code inner works.
You initialize classimg to be a 51x51x3xnumFileNeg matrix of zeros. You use the zeros function, so the datatype is double. To see this clearly, call your function from the command window, and then type "whos" to see both the size and datatype of classimg.
As Mike correctly points out, since you initialize classimg using zeros, and the default data type is double, your image data will be converted to double from whatever data type imread returns (often uint8).
If you would like classimg to be the same data type as your images (which I'm assuming all have the same type), you can load one image, get its class, and initialize classimg with that specific class. Here's how you could rewrite your function:
function classimg = loadImages(classdir, ext)
neg = dir(fullfile(classdir, ext));
numFileNeg = numel(neg);
tempImage = imread(fullfile(classdir, neg(1).name));
classimg = zeros(51, 51, 3, numFileNeg, class(tempImage));
classimg(:, :, :, 1) = tempImage;
for i = 2:numFileNeg
classimg(:, :, :, i) = imread(fullfile(classdir, neg(i).name));
end
end
Note that I made a couple of other changes. I used fullfile instead of concatenation of the directory and file names, since it handles any issues with file separators for you. I also used numel to get the number of files as Justin suggested in a comment.
vector <int>v;
vector <int>:: iterator it,it1;
it=v.begin();
it1=v.end();
v.insert(it,12); // in this line doesn't matter what i write it or it1
it=v.begin(); it1=v.end(); // here *it=12, also it is first element and it1 = last element + 1
v.insert(it1,15); // if i write it instead of it1, then v contains 15 12
it=v.begin(); it1=v.end();
cout<<*(it+1); // this line outputs 15;
if my comments are correct, then how v.insert(v.end(), any number); can be correct?
Never debug comments. Always debug the code. :)
std::vector::insert(iterator, value) inserts the value before the iterator passed in. Since std::vector::end() is passed to insert(), this inserts 15 before the end of the vector - that is, after 12. Therefore when the element after the first element is printed, this should print 15.
iterator insert( iterator pos, const T& value ); inserts the element before the specified position.
So here it will insert at the back, and then the end position will shift by one.
Your it1=v.end() will be invalidated by the insert, so you'll need to re-set it. (Thanks #Mgetz)
To insert into an empty vector, you can still insert to end. Just because end() == begin() in an empty vector doesn't mean they're set to the same thing.
I need to change all the value labels of all my variables in my spss file to be the value itself.
I first tried -
Value Labels ALL.
EXECUTE.
This removes the value labels, but also removes the value entirely. I need this to have a label of some sort as I am converting the file and when there is no values defined it turns the value into a numeric. Therefore, I need the all value labels changed into numbers so that each value's label is just the value - value = 1 then label = 1.
Any ideas to do this across all my variables??
Thanks in advance!!
Here is a solution to get you started:
get file="C:\Program Files\IBM\SPSS\Statistics\23\Samples\English\Employee data.sav".
begin program.
import spss, spssaux, spssdata
spss.Submit("set mprint on.")
vd=spssaux.VariableDict(variableType ="numeric")
for v in vd:
allvalues = list(set(item[0] for item in spssdata.Spssdata(v.VariableName, names=False).fetchall()))
if allvalues:
cmd="value labels " + v.VariableName + "\n".join([" %(i)s '%(i)s'" %locals() for i in allvalues if i <> None]) + "."
spss.Submit(cmd)
spss.Submit("set mprint off.")
end program.
You may want to read this to understand the behaviour of fetchall in reading date variables (or simply exclude date variables from having their values labelled also, if they cause no problems?)
Recently I encounter an interview question. I was required to write code for expression evaluation. The expression format looks like this:
B=10;
A={
A=100;
B=BDE;
C=C;
D={
A=windows;
B=mac;
C={
A=redhat;
B=ubuntu;
};
};
A+={
A=200;
E=1000;
};
To represent the key of the expression, period delimitated method is used. For example, A.B represents the element B in Map A, and the value of A.B is BDE; similarly, the value of A.D.C.A is redhat. the the represent string is called 'path expression'.
the configuration also support append and override operation. for the above example, we use += operation to append or override the value in Map A. now the value of A.A is 200, and the value of A.E is 1000;
Now, given a configuration strings and the key path of configuration, I was required to return the value of configuration based the configuration strings.
Rules
1) the key name and his value only contains alphabet(A-Z,a-z) and number(0-9), no other characters;
2) if cannot find the value or the expression point to a map, please output "N/A"
3) if find the value, please output the value. no spaces when output the value.
Input and Output
there are three part sin the input. the first line contains two integers indicates the number of congiruation lines(M) and the number of expressions(N).
M<=100, N<=100. the following M lines are the confugration and the last N lines are expression. every configuration line contains one or more configurations. every line length less than 1000.
Input :
2 2
A={A=1;B=2;C=3;E={A=100;};};
A+={D=4;E={B=10;C=D;};};
A.E.B
B.D.E
Output
A.E.B=10
B.D.E=N/A
My thoughts
I was thinking about using a N-nary tree to represent the expression. For example, the expression: A = {A = 1;D = 1;B = {C = 1,D = {D = 1,F = 2};};}; can be represented as:
(A,-)
/ | \
(A,1) (D,1) (B,-)
/ \
(C,1) (D,-)
/ \
(D,1) (F,2)
Since a N-nary tree can be represented as a binary tree. Thus, all append or search operations would be either the insert or search operations for a binary tree. It seems that this approach works. But I am wondering if there is a better way to approach this problem?
I am thinking about putting all children in a hash map (since that's what interviewers like)
Node{
String val;
HashMap<String, Node> children;
Node(int val){
this.val = val;
children = new HashMap<String, Node>();
}
}