How do I write a comment to a PropertiesConfiguration file? - configuration-files

Given one of these instances: org.apache.commons.configuration.PropertiesConfiguration I want to write a comment. How?
pc = new PropertiesConfiguration();
writeComment("this is a comment about the stuff below"); // HOW DO I WRITE THIS?
pc.addProperty("label0", myString);
writeComment("end of the stuff that needed a comment.");
Edit: I have a crude solution. Hopefully it can be improved upon.
Here's the best I could do. It leaves an extraneous line in the file.
pc = new PropertiesConfiguration();
writeComment(pc, "The following needed a comment so this is a comment.");
pc.addProperty(label0, stuff0);
writeComment(pc, "End of the stuff that needed a comment.");
...
private void writeComment(PropertiesConfiguration pc, String s)
{
String propertyName = String.format("%s%d", "comment", this.commentNumber++);
pc.getLayout().setComment(propertyName, s + " (" + propertyName + ")");
// make a dummy property
pc.addProperty(propertyName, ".");
// put in a dummy right-hand-side value so the = sign is not lonely
}
One of the problems with this approach is that the PropertiesConfiguration doc is a little vague about the layout. It does not explicitly say that the comment will appear above the dummy line so there seems to be the risk that PropertiesConfiguration is free to re-arrange the file on subsequent invocations. I have not even seen an guarantee that property line order is preserved so I cannot guarantee that the comment (and dummy line) will always be above the property that the comment applies to: property label0. Of course, I'm being a little paranoid here. However, the doc does say that layouts are not guaranteed to remain unmodified. Hopefully somebody can come up with something without the dummy line and a Java doc or website guarantee on the position of the comment relative to the property it is meant to comment on. Edit: You might wonder why I would create a dummy property instead of just attaching the comment to one of the properties that would already be in the file. The reason is because I want a comment to introduce a block of properties and changes (new ones, or a switch in the order) are possible. I don't want to create a maintenance problem. My comment should say "this is the section for data mining results" or "this is the section for the schedule" and I should never have to revisit this.

Comment like this?
# This is comment

The PropertiesConfiguration JavaDoc documents
Blank lines and lines starting with character '#' or '!' are skipped.
EDIT: Ok, you want to write the comment from code. Maybe - if you just need to write a property file - you can use the PropertiesConfiguration.PropertiesWriter and its writeComment method like this:
FileWriter writer = new FileWriter("test.properties");
PropertiesWriter propWriter = new PropertiesWriter(writer, ';');
propWriter.writeComment("Example properties");
propWriter.writeProperty("prop1","foo");
propWriter.writeProperty("prop2", "bar");
propWriter.close();
The property file will look like this:
# Example properties
prop1 = foo
prop2 = bar
Update
Summarized: The PropertiesConfiguration does not provide the functionality you are looking for.

Related

How do you create branching logic/skipping rules in a Microsoft Access form?

I'm creating a very simple Access database with a table and corresponding form. For some questions on the form, I'd like to disable following questions, or hide them using branching logic.
For example, in my form I have a combobox question that asks: Are you a smoker? - "Yes", "No", "Prefer not to answer". The following question is: If yes, how often do you smoke? If they chose the answers "No" or "Prefer not to answer" for the first question, then I don't want the second question to be visible/enabled.
I've been searching for a way to do this and the easiest way seems to be setting the Visible property of textbox "If yes, how often do you smoke?" to No. After that, I go to question "Are you a smoker?" and go to Event Procedure in the Properties menu. This brings up a VBA code editor with the following text:
Option Compare Database
Private Sub Text969_Click()
End Sub
Private Sub Combo367_Click()
End Sub
I've been looking at different pages but I can't seem to get the code to work. For the particular question I'm asking, the name of the form is "Chronic Smokers" and the field for the first question is named "Are you a smoker." and the second question is named "If yes, how often." This is the code I've been trying and it doesn't work, but I can't seem to figure anything else out:
Option Compare Database
Private Sub Text969_Click()
End Sub
Private Sub Combo367_Click()
If Chronic Smokers.Combo367='Yes' then
Chronic Smokers.If yes, how often.Visible = True
Else
Chronic Smokers.If yes, how often.Visible = False
End if
End Sub
I think part of my problem is that I don't know the way the naming conventions or syntax for this code works. I have a feeling part of the problem is that I have blank spaces without underscores in the names If anybody can help me out with this, I'd really appreciate it!
VBA code could be as simple as Me.[how often].Visible = Me.Combo367 = "Yes". No If Then Else needed. Code will need to be in combobox AfterUpdate as well as form Current events, not Click event. Code will apply to ALL instances of control, not just the current record.
NOTE: use of Me qualifier is shorthand for form/report object code is behind.
If you prefer to use If Then Else, correct syntax would be:
With Me
If .Combo367 = "Yes" Then
.[how often].Visible = True
Else
.[how often].Visible = False
End if
End With
Suggest you explore Conditional Formatting. It allows to enable/disable textboxes and comboboxes dynamically per record without VBA. Controls will still be visible but 'greyed out'.
And yes, strongly advise not to use spaces nor punctuation/special characters (underscore is only exception) in naming convention nor reserved words as names. If you do, then enclose in [ ] as shown above. Better naming would be ChronicSmokers and HowOften. And give objects more meaningful names than the defaults assigned by Access.

Getting the user's name without directly asking for it (Watson Assistant)

I'm creating a chatbot for fun and want to implement something to collect the user's name, but only if he says something like "my name is ..." or close to that; the intention of giving the name would come from the user, the bot won't ask for it, maybe only suggest it. Kind of like in Google Assistant, I think. So, it could be given at any time the user wants.
My idea is:
1st create an intent with different ways the user would tell his name to the bot (like in the example above).
2nd use slots and, if the intent is detected, save it as a variable. So far, I've managed.
3rd is the part that I'm stuck in, since it's only an idea and I don't know how I'd do it. Before saving the whole text as a variable, I'd like to delete the part that's included in the intent (my name is) and save only the rest in the variable. So, for example, the user says "my name is XXX"; the command deletes the "my name is" part and saves only "XXX" in the $name intent.
I don't know if this'd be possible, since I don't know coding. I used some special syntax before, like to capitalize the first letter of some other variable, but I don't really know how to use the JSON editor.
Is my idea viable? I don't know how I'd delete the intent corresponding portion and save only the remaining part as the intent. Dunno what would be the command for that, nor where I'd write it.
You can suggest something else if you have an idea.
Last thing, I'm created the skill in portuguese, so there's no access to the #sys-person entity.
Thanks for reading.
I use portuguese skills and face the same issue. I see two solutions, althougt they are not perfect:
Using intents:
When the intent is identified, the bot asks the name again, telling the user that he should only say his name, e.g without "my name is", then store the whole input on a context variable, using:
<? input.text ?>
For embedding such logic inside slots, you probaly will need to use digressions.
But, this is boring to the user.
Using entities:
Entities identification carries along they start and end position in the input text, but intents not. With this, is possible to slice the input, cutting the entity:
<? input.text.substring(entities.name.location[1], input.text.length()) ?>
Entites would be "My name is", "People call me", "I'm called", "I'm baptized", "I was baptized".
So, "Hello, my name is Gustavo", would be cut after "my name is" ending, resulting in "Gustavo". Additional input in the beggining is ignored, but problems arrise with additional input after the name. Also, you need to define more "my name is" like entities, likely all possibilities, than would need if using intents, cause even with fuzzy matching, entities identification doesn't take in account synonymus and similar meaning words.
https://cloud.ibm.com/docs/assistant?topic=assistant-dialog-methods#dialog-methods-strings-substring
https://cloud.ibm.com/docs/assistant?topic=assistant-expression-language#expression-language-access-entity

Swift - Getting Error while using replacingOccurrence

So I'm taking Udacity's Swift for Developers course. I attempted to look at the forums for this question but oddly, they were quiet. This is the programming prompt:
var forwardString = "stressed"
var backwardsString = forwardString.characters.reversed()
print(backwardsString)
var lottaLikes = "If likeyou wanna learn Swift likeyou should build lots of small apps cuz it's likea good way to practice."
var noLikes = lottaLikes.replacingOccurrences(of:"like", with:"")
print(noLikes)
For whatever reason, I keep getting this error message:
Be sure that you have replaced all occurences of the word "like" and removed any extra spaces.
What am I missing here? If you need clarification on this I would be happy to provide it.
Thank you
It may be that your code gets the job done, but only because your variable lottaLikes is written in a weird way. You usually would have two spaces surrounding the word "like" so just removing the word would leave 2 spaces in a row. I would suggest writing the following line:
var noLikes = lottaLikes.replacingOccurrences(of:"like ", with:"")
It may be that Udacity is not checking the actual output, but the code itself. If so, It may be looking for something like I wrote above.
If this still does not work, you may want to write another line like so:
var noExtraSpaces = noLikes.replacingOccurences(of: " ", with: " ")

Extract comments of specific annotation of a PDF using iText

using iText I am able to get a list of annotations of a PDF. It seems that even replies are annotations themselves.
Extracting them, I look at the contents of the PdfDictionary using this
Set<PdfName> keys = annot.getKeys();
for (PdfName key : keys) {
System.out.println(key + "," + dictionary.get(key));
}
However, I cannot pinpoint which PdfName I need to use in order to identify replies belong to that certain annotation.
Please take a look at the official documentation, more specifically at the answer to the example How to add an "In Reply To" annotation?
In this answer, I explain how to add an "In reply to" to an existing annotation. Let's open the resulting PDF and let's take a look inside:
As you can see, the annotation with the content "Hello PDF" is stored in an object with number 1. It is an annotation in reply to (IRT) the annotation with object number 2.
In answer to your question: you need to look at the key with value PdfName.IRT and this will give you the object number of the annotation to which the current number is a reply.

SSIS Formatting input from flat file

I'm a SSIS newbie. I wanna format the inputs of my flat file before saving the entries in a database table. Initially I created a flat file as follows:-
"1","Superman","Metropolis"
"2","Batman","Gotham"
"3","Spiderman","New York"
"4","James Bond","London"
"5","Green Lantern","Oa"
The solution for stripping this was simple as shown here http://www.mssqltips.com/sqlservertip/1316/strip-double-quotes-from-an-import-file-in-integration-services-ssis/
But now i have created a new similar package and given my input file like this:-
"6", "TMNT", "Sewers NY"
"7", "Iron Man", "New York"
Note here I've put a space after the delimiting comma. Now when I follow the above method the first number field stripped of the double quotes, but rest of the entries retain their quotes. Any idea how to work around this? One suggestion on a similar question on stackoverflow mentioned use of a "Transformation script". Since I'm a newbie can anyone please throw light on this method?
Yes, you can use Script component transformation. Select all columns, and change them to ReadWrite. The code:
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
Row.ID = Row.ID.Replace("\"", string.Empty);
Row.Movie = Row.Movie.Replace("\"", string.Empty);
Row.City = Row.City.Replace("\"", string.Empty);
}
If you want to trim the spaces you can use
Row.ID.Replace("\"", string.Empty).Trim();
You would also need to take care if you want to preserve the values that are " ". Please post if the suggestion was helpful or if you have any questions.
In the 'General' tab you can set a text qualifier of ". Then those quotes will be ignored.
Then you don't need to write error prone script when there is a simple solution.