I'm getting crazy, cause I cannot find what are the "default" keys you would have in a PDF Document.
For example, if I want to retrieve an hyperlink from a CGPDFDocument, I do this:
CGPDFStringRef uriStringRef;
if(!CGPDFDictionaryGetString(aDict, "URI", &uriStringRef)) {
break;
}
In this case, the key is "URI". Is there a document explaining what are the keys of a CGPDFDictionary?
It's absurd that you would have to go read 1300 page long specs just to find what keys a dictionary contains, a dictionary that could contain anything depending on what kind of annotation it is.
To get a list of keys in a CGPDFDictionaryRef you do:
// temporary C function to print out keys
void printPDFKeys(const char *key, CGPDFObjectRef ob, void *info) {
NSLog(#"key = %s", key);
}
In the place where you're trying to see the contents:
CGPDFDictionaryRef mysteriousDictionary; // this is your dictionary with keys
CGPDFDictionaryApplyFunction(mysteriousDictionary, printPDFKeys, NULL);
// break on or right after above, and you will have the list of keys NSLogged
The Adobe PDF Reference describes all of the keys.
The keys in a dictionary depend on the actual object the dictionary represents (a page dictionary has other keys than an annotation dictionary). The Adobe PDF reference describes all these objects and their keys.
Related
I need return list of keys, but next code return me only keys values.
string confpath = buildPath(getcwd, "config.ini");
if (!exists(confpath)) throw new Exception("ERROR: config.ini do not exists");
auto config = Ini.Parse(confpath);
foreach (key; config.keys())
{
writeln(key);
}
config.ini:
images = C:\images
photos = D:\photos
pictures = E:\stuff\pictures
Expected output:
images
photos
pictures
code output:
C:\images
D:\photos
E:\stuff\pictures
I looked at sources, but do not found where I can return only keys.
In dini, the keys property returns the _keys associative array, which is a
string[string].
So your foreach should be:
foreach (key, value; config.keys())
{
writeln(key);
}
Alternatively, you can call the associative arrays keys property to get just the keys.
Edit:
IMO, the naming here is a little confusing. I'd personally call dini's keys function "asMap" or something like this, making it obvious that your getting back a mapping of keys=values.
If you use my ini wrapper you can return the keys by .keys from IniSection. IMO "dini" is not that good and offers a "non-userfriendly" inifile wrapper. Besides it doesn't follow SafeD which IMO an ini wrapper definitely should as you shouldn't need pointers for parsing a text-format.
Ex.
auto keys = ini.getSection("Root").keys;
Or .values for the values.
You can get it here:
https://github.com/BaussProjects/baussini/
I'd like to generate a list of key bindings that are unpopulated in SlickEdit 18.0.0+
Is there a simple way to do this?
Currently, when I write a new macro, I have to hunt and peck trying various combinations to find if there is a key sequence I can live without.
The only thing I found on the interweb was a mailing list feature request for this, and the SlickEdit employee recommended using the command line interface instead of a bound hotkey. Not quite what I'm hoping for.
I am using v17 but 'unused keys' is an infinite set since it is a multi-key hotkey system. I imagine it can be done based on the existing key-tree, but I would not want to write it.
If you are looking for a quick manual way to find empty key-paths, use the following:
// list keys in sorted fashion to new buffer
_command list_keydefs()
// Find command assigned to a key-path
_command what_is()
// Find commands assigned to key-paths
_command what_are()
// Find key-paths assigned to command
_command where_is(_str commandName='', _str quiet='',_str separatorChar=',') name_info(COMMAND_ARG',')
// Bind to a key
_command bind_to_key(_str commandName='') name_info(COMMAND_ARG',')
// Bind current word (proc name) to key
_command bind_cur_word_alt(){
if (command_state()) {
return(0);
}
_str s=cur_word(0);
if (s==''||!is_cmd(s)) {
s=current_proc_name(false);
}
if (!is_cmd(s)) {
_message_box(s' is not a command');
return(0);
}
_str sa=letter_prompt('Number of Keys or 0 to Quit','1234567890');
if (sa==''||sa=='0') {
_message_box(1);return(0);
}
_str ss='-'sa' -r 's;
bind_to_key(ss);
ss=where_is(s,1);
sticky_message(ss);
}
// utils
_command is_cmd(...){
_str p=current_proc(false);//was current_proc_name
if (arg()==1) {
p=arg(1);
}
return(find_index(p,COMMAND_TYPE)!=0);
}
I am making a simple app where the user can create severals objects which are saved with CoreData.
My problem is, I want each object to have an image linked to it. The image is brought by the iphone camera or the user personal Camera roll, so the images will have a pretty high weight (> 1MB each I think).
I read that when the weight of images is that high, the good way to handle this is to save the images in the documentsDirectory folder, and save the path to coreData. I achieved this pretty easily.
But how do I find a path name for the image to be linked to an unique object? CoreData does not really handle unique IDs, and two objects can have the same name... I searched around objectID but it's not working really good and I'm not sure it's the good way to handle this.
Do you have any idea? Is there an other simple way I am totally missing? Thank you in advance.
use coredata's objectID as identifier
id uri = [self sanitizeFilename:coreDataObject.objectID.URIRepresentation];
[NSString stringWithFormat:#"%#.png", uri];
helper sanitizeFilename:
- (NSString *)sanitizeFileNameString:(NSString *)fileName {
NSCharacterSet* illegalFileNameCharacters = [NSCharacterSet characterSetWithCharactersInString:#"/\\?%*|\"<>"];
return [[fileName componentsSeparatedByCharactersInSet:illegalFileNameCharacters] componentsJoinedByString:#""];
}
Just create an object_id number property in your CoreData model entity description and each time a new object is created increment this property by one and assign it to the object, then use a naming convention like
[NSString stringWithFormat:#"object_%d_img.png", idNumber];
And save it to NSDoctumentsDirectory.
Then in object's - (void)prepareForDeletion method delete the image.
As for how to increment the id value, create a method that will fetch an object with biggest id value - simply get all objects with sort descriptor by id desc and use it + 1 when creating a new entity.
Thanks to #Daij-Djan. I created version for Swift:
var itemObjectId:String = item.objectID.URIRepresentation().absoluteString!
var fileName = NSString(format:"%#.png", FileHelper.sanitizeFileNameString(itemObjectId)) as String
Helper for sanitize:
struct FileHelper {
static func sanitizeFileNameString(fileName:String) ->String {
let illegalFileNameCharacters:NSCharacterSet = NSCharacterSet(charactersInString: "/\\?%*|\"<>")
let components : [String] = fileName.componentsSeparatedByCharactersInSet(illegalFileNameCharacters)
let joinedString = join("", components)
return joinedString
}
}
I think you'll need to generate the unique id by your self. Since a user can have several objects. so maybe the image id could be named as such
userId-objectId-somesalt
save the value to the object's path
I am using the NameFinder API example doc of OpenNLP. After initializing the Name Finder the documentation uses the following code for the input text:
for (String document[][] : documents) {
for (String[] sentence : document) {
Span nameSpans[] = nameFinder.find(sentence);
// do something with the names
}
nameFinder.clearAdaptiveData()
}
However when I bring this into eclipse the 'documents' (not 'document') variable is giving me an error saying the variable documents cannot be resolved. What is the documentation referring to with the 'documents' array variable? Do I need to initialize an array called 'documents' which hold txt files for this error to go away?
Thank you for your help.
The OpenNLP documentation states that the input text should be segmented into documents, sentences and tokens. The piece of code you provided illustrates how to deal with several documents.
If you have only one document you don't need the first for, just the inner one with the array of sentences, which is composed by as an array of tokens.
To create an array of sentences from a document you can use the OpenNLP SentenceDetector, and for each sentence you can use OpenNLP Tokenizer to get the array of tokens.
Your code will look like this:
// somehow get the contents from the txt file
// and populate a string called documentStr
String sentences[] = sentenceDetector.sentDetect(documentStr);
for (String sentence : sentences) {
String tokens[] = tokenizer.tokenize(sentence);
Span nameSpans[] = nameFinder.find(tokens);
// do something with the names
System.out.println("Found entity: " + Arrays.toString(Span.spansToStrings(nameSpans, tokens)));
}
You can learn how to use the SentenceDetector and the Tokenizer from OpenNLP documentation documentation.
As per a previous question, I have reluctantly given up on using IB/Xcode4 to edit an NSPredicateEditor and done it purely in code.
In the GUI way of editing the fields, key paths can be specified with spaces, like 'field name', and it makes them work as 'fieldName'-style key paths, while still displaying them in the UI with spaces. How do I do this in code? When I specify them with spaces, they don't work. When I specify them in camelCase, they work but display in camelCase. I'm just adding a bunch of NSExpressions like this:
[NSExpression expressionForKeyPath:#"original filename"]
The proper way to get human readable strings in the predicate editor's row views is to use the localization capabilities of NSRuleEditor and NSPredicateEditor.
If you follow the instructions in this blog post, you'll have everything you need to localize the editor.
As an example, let's say your key path is fileName, you support 2 operators (is and contains), and you want the user to enter a string. You'll end up with a strings file that looks like this:
"%[fileName]# %[is]# %#" = "%1$[fileName]# %2$[is]# %3$#";
"%[fileName]# %[contains]# %#" = "%1$[fileName]# %2$[contains]# %3$#";
You can use this file to put in human-readable stuff, and even reorder things:
"%[fileName]# %[is]# %#" = "%1$[original filename]# %2$[is]# %3$#";
"%[fileName]# %[contains]# %#" = "%3$# %2$[is contained in]# %1$[original filename]#";
Once you've localized the strings file, you hand that file back to the predicate editor, and it'll pull out the translated values, do its magic, and everything will show up correctly.
If you don't want to localize everything, just map the key paths consider overriding value(forKey:) in your evaluated object like this:
class Match: NSObject {
var date: Date?
var fileName: String?
override func value(forKey key: String) -> Any? {
// Alternatively use static dictionary for mapping key paths
super.value(forKey: camelCasedKeyPath(forKey: key))
}
private func camelCasedKeyPath(forKey key: String) -> String {
key.components(separatedBy: .whitespaces)
.enumerated()
.map { $0.offset > 0 ? $0.element.capitalized : $0.element.lowercased() }
.joined()
}
}