So far I have seen that the majority of responses to this kind of question advice using a list.
All well and good in many circumstances, however not when needing to assign a specific variable name.
Please read and understand that I'm not asking the same question as has been before before downvoting this, if the answer is truly the same (use list/dict) please explain how this is implemented in my specific case,
In my situation I have a pyqt5 gui and I want to change the text of the labels in certain circumstances:
for layer in layerlist:
# reads all layers into a dictionary
layers[layer] = gpd.read_file(gdb_path, driver="FileGDB", layer=layer)
gdf = layers[layer]
if gdf.empty: # loop to find empty datasets
self.lab_1.setText("Empty dataset")
Obviously using self.lab_1 as a static variable will be of little use.
More useful would be to have the label be the same as the layer name so it can address the cotrrect label in the gui.
if gdf.empty:
self. + layer + .setText("Empty dataset")
Using + works fine for adding variables to strings, but wont work in this case. I've done this before in things like php, is it possible in Python, if so how?
Related
I am new to this field, this question might look dumb to some of you but please bear with it.
I have created a keras model which works well. I can save it in .hdf5 format using model.save("model_name.hdf5) which is good.
Main question is if there is any other format i can save my model in so that it can be used in c++/android/JavaScript. Is this even possible to do so?? If you are thinking why I am asking for all 3 languages, its because I have 3 projects each of them use respective language.
Thanks for any help in advance.
The answer depends on what you are going to save and use in another language.
If you just need the architecture of the model to be saved, you may save it as JSON, which can later be used in any other platform and language you are going to use.
model_json = model.to_json()
If you also need the weights and biases, I do not know any specific tool, but you can simply read the stored data in python, create a multidimensional array, and then save it in a file appropriate for any of the languages you need. For example, the weights of the second layer can be found in model.layers[2].get_weights().
Finally, if you want to run the model in another language, you need to implement the for-loops that make the processing. You might find some conversion tools for your target language. For example, for C, this tool can help.
I'm not a native English speaker and I'm wondering how's better to naming a variable with multiple words.
For example, I have two urls. One is for querying and the other is for submitting.
Should them be named as url_query, url_submit? Or querying_url, submitting_url? Or query_url, submit_url? Or things like submission_url?
I prefer url_query and url_submit. They are neat if I have a lot different urls for different purposes. But it sounds strange if I say it out.
This is a highly opinionated subject and it may be best to consult a specific coding style of your choice.
However, in general you want you variable names to be easily understood and readable.
For this reason items such as url_submit and url_query may be better option, as both are fairly understandable.
There are many different naming conventions, but the most important factor here is readability and implementation. Remember that comments will also help the readability as well.
You can name them however they feel right to you. Typically I camelCase them however instead of using underscores.
submitUrls/queryUrls
Try to think globally however as you may have these replicated in other pages and you may be able to build off your existing names like *action/*Thing(ie submit + what to submit "submitUrls")
Also, If something doesn't seem to make a good deal of sense to you when you're naming it. It is wise to add a line of comments in to identify what this function does later down the road if you have a bunch of functions named of actions and items.(Things)
I have a list of medicine names(regular_list) and a list of new names(new_list).I want to check whether the names in the new_list are already present in the regular_list or not.The issue is that the names new_list could have some typo errors and I want those name to be considered as a match to the regular list. I know that using stringdist is a solution to the problem but I need a machine learning algorithm
As it was already mentioned here machine learning to overcome typo errors , machine learning tools are too much for such task, but the simplest possibility would be to merge those approaches.
On one hand, you can compute the edit distance between given word x and each of the dictionary words d_i. Additionaly, you can traing per-word classifier
c(d_i, distance(x,d_i))
returning True (class 1) if a given edit distance has been learned to be sufficient to consider x a missspelled version of d_i. This can give you more general model then not using machine learning, as you can have different thresholds for each dictionary word (some words are more often misspelled then others), but obviously, you have to prepare a training set in form of (misspelled_word, correct_one) (and add also (correct_one, correct_one).
You can use any type of binary classifier for such task, which can work on "real" input data.
I am using Jena and Java, and am reading a CSV file. For each line of the file there is a subject resource. Two subject resources, on adjacent lines, might have share the same value of a field in the line (e.g: both lines have the same process id). In this case, I need to combine the two subject resources as each one represents a sub-process in production (for example).
My question is: how can I reference those two resources dynamically so that I can combine them? I came to the idea that when I find that they share the same property to store them in an array resource subjects. Is it the right approach?
This question would be a lot easier to answer if you could show some sample data. As it is, I think you're focusing on the wrong bit of the question. If you can decide clearly what it means to have two rows in your CSV with identical process, and then you decide how you're going to encode that meaning in your RDF model, then the question of how to write the code - as an array or whatever - will be much clearer.
For example (and I'm going to make up some data here - as I said, it would be easier if you show an actual example), suppose your CSV contains:
processId,startTime,endTime
123,15:22:00,15:23:00
123,16:22:00,16:25:00
So process 123 has, apparently two start and end time pairs. If you model this naively in RDF, you'll end up with a confusing model:
process:process123
a :Process;
process:start "15:22:00"^^xsd:time;
process:end "15:23:00"^^xsd:time;
process:start "16:22:00"^^xsd:time;
process:end "16:25:00"^^xsd:time;
.
which would suggest that one process had two start times (and two end times) which looks nonsensical. However, it might be that in reality you have a single process with multiple episodes, suggesting one way to model it, or a periodic process which occurs at different times, or, as you suggested, sub-processes of a parent process. Or something else entirely (I'm only guessing, I don't know your domain). Once you are clear what the data means, you can produce a suitable RDF model. For example, an episodic process might be:
process:process123
a :Process;
process:episode [
a process:Episode;
process:start "15:22:00"^^xsd:time;
process:end "15:23:00"^^xsd:time;
];
process:episode [
a process:Episode;
process:start "16:22:00"^^xsd:time;
process:end "16:25:00"^^xsd:time;
]
.
Once the modelling is clear in your mind, I think you can see that the question of how to produce the desire RDF triples from Java code - and whether or not you need an array - is much clearer. Equally importantly, you can think in terms of the JUnit tests you would write to test whether your code is behaving correctly.
I am having a method in which there are more then 7 parameters ,type of all the parameters are different.
Well my question is it fine or i should replace all parameters with the single class(which will contaion all parameters as a instance variable).
Well my question is it fine or i should replace all parameters with the single class
7 is way too much. Replace with a class. With my VS custom theme and fonts settings Intellisense wouldn't fit on the screen when there is a method with so many parameters :-) I find it more readable and easier to understand when working with classes.
Of course those are just my 2 cents and it's subjective. I've seen people writing methods with many many parameters.
Well, there are places where I'd consider that okay - but they're few and far between. I would generally consider using a "parameter class" instead.
Note that it doesn't have to be an "all or nothing" approach - would it make more sense to encapsulate, say, 4 of the parameters together? Would that allow the new class to be used in other methods?
Other thing to consider is whether the method might be doing too much - does the functionality of the method definitely feel right as a single cohesive unit?
Thare are Microsoft APIs with even more parameters; anyway I agree with #Darin, a class could be a good solution, clear and efficient that can avoid passing parameters in the right order... so for example if you change order for oen without using refactoring you're in a mess...
Consider also if that class can be used in other parts of the program...
I somewhat agree with all given answers. However it might be a good idea to break down the method into smaller parts as Jon is suggesting. Usually when you have a situation like this means that the method is doing too much. Typically methods should have 1 or 2 parameters at most. While you would achieve the same by replacing all your parameters with a class parameter you might just be hiding the bigger issue. Is there any chance you can post the method or describe what it's doing?
As a rule of thumb, if you can't fit the entire method, including declaration onto 1 screen, it's too big. Programmers will normally recommend to break down methods to make them reusable. But, it also makes perfect sense to break them down to increase readability.