I found a strange issue like even If I explicitly mention the datapath to be /data/local/tmp/tesseract/, the TessBaseAPI uses the tessdata inside /data/data/tesseract/ (Only if it exists). If tesseract directory does not exist inside /data/data folder then the given path is taken.
I almost searched the entire TessBaseAPI.java file, but I couldn't find the default path.
Following are the code:
String TESSBASE_PATH = "/data/local/tmp/tesseract/";
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(TESSBASE_PATH, "eng");
Can you please let me know from where the default datapath is taken?
There's no "default" data path. Only the path supplied to the init() method is used. Check out the code for the init() method--you'll see where the API throws an IllegalArgumentException if the data file is not in the specified location.
Related
===Update: Using org.reflections:reflections:0.9.11
Looking to use the following line to pull a list of class names from Kotlin source...
Reflections.getSubTypesOf(Any::class.java)
However I receive a message that Kotlin class files aren't being seen when I run the following script...
val classLoader = URLClassLoader(this.getDirectoryUrls(), null)
println("retrieved class loader")
val config = getConfig(classLoader)
println("retrieved source config")
val reflections = Reflections(config)
println("retrieved reflections")
// For 3 paths: Reflections took 3 ms to scan 3 urls, producing 0 keys and 0 values
=== Update: The 3 urls added by "getDirectoryUrls()" are directories containing kotlin class source files.
Below is my config... ideas?
private fun getConfig(classLoader: ClassLoader): ConfigurationBuilder {
val config = ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(classLoader))
// .setScanners(SubTypesScanner(false), ResourcesScanner())
if (!packagePath.isNullOrBlank()){
System.out.println("looking in package [$packagePath]")
config.filterInputsBy(FilterBuilder().include(FilterBuilder.prefix(packagePath)))
}
config.addClassLoader(classLoader)
config.setScanners(SubTypesScanner(), TypeAnnotationsScanner())
return config
}
Setting SubTypesScanner(false) seems to be required to get any types with getSubTypesOf(Any::class.java) (that parameter itself stands for excludeObjectClass). Looking at the bytecode of Kotlin classes you immediately see, that they are actually looking the same as Java classes. There is no Any-superclass there. Note that Kotlins Any is actually also in other means very similar to Javas Object (but not the same, check also the following answer to 'does Any == Object'). So, we need to include the Object-class when scanning for subtypes of Any (i.e. excludeObjectClass=false).
Another problem could be the setup of your URL array. I just used the following to setup the reflections util:
val reflections = Reflections(ConfigurationBuilder()
.addUrls(ClasspathHelper.forPackage("my.test.package"))
.setScanners(TypeAnnotationsScanner(), SubTypesScanner(false)))
which will resolve all matching subtypes and will return subtypes also for Any.
reflections.getSubTypesOf(MyCustomSuperType::class.java).forEach(::println)
reflections.getSubTypesOf(Any::class.java).forEach(::println)
Analysing further: you mention "Kotlin class source files"... if that means you are pointing to the directory containing the .kt-files, then that is probably your problem. Try to use the directory which contains the .class-files instead. Moreover, ensure that the classes are on the classpath.
Maybe you know already, maybe not? Note also that if you have a (classes) directory, say /sample/directory, which is on the classpath and which contains a package, say org.example (which corresponds to the folder structure org/example or full path /sample/directory/org/example) then you must ensure that you add an URL similar to the following:
YourClass::class.java.classLoader.getResource("")
and not:
YourClass::class.java.classLoader.getResource("org.example")
// nor:
YourClass::class.java.classLoader.getResource("org/example")
You basically require the "base" directory (in the example /sample/directory or from the view of the classloader just "")) where to lookup the packages and not the package itself. If you would supply one of the latter URLs, only classes that are in the default package (within /sample/directory/org/example) would actually be found, which however is a rather uncommon setup.
In this blog post, some prerequisite code for getting started using SQLite in Windows Store Apps is given, for adding to the OnLaunched method of App.xaml.cs:
// Get a reference to the SQLite database
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "customers.sqlite");
My question is: Can I use any arbitrary value to replace the "customers.sqlite" part, or does it have to match something else in my code, such as the name of my table definition class (in my case "PhotraxCoreData.cs" which, according to Mr. Green's suggestion, I added below a newly-created "Models" folder)?
My understanding is that, once I've got those classes defined (I do), and the code above in App.xaml.cs, along with this there (adapted for my SQLite classes):
using (var db = new SQLite.SQLiteConnection(this.DBPath))
{
// Create the tables if they don't exist
db.CreateTable<PhotraxBaseData>();
db.CreateTable<PhotraxNames>();
db.CreateTable<PhotraxQueries>();
}
...SQLite tables based on those classes I specified will be created, and have the name "customers.sqlite" (provided I don't change it).
So, can I use:
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "platypus.sqlite");
...or must it be something like:
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "PhotraxCoreData.sqlite");
That database name is just a file name.
The directory must be accessible by your app, but the file name can be anything.
AS CL says, the file name can be anything the app has direct access to. Windows Store apps have limited access to the file system, so the sqlite database must be in either the apps install location (read only) or it's app data folder (read write). A common pattern is to ship a seed database in the app package and then copy it from the install location to app data on first use so it can be written to.
I'm using grunt-init to build a template for a site structure I repeat regularly.
The template.js file uses the init.copyAndProcess function to customize most of files but a few of them get corrupted by the file processing (some fonts and image files) and I want to include those files in the 'noProcess' option. If these files all existed in the same directory, I could use the noProcess option as mentioned in the documentation [ See: http://gruntjs.com/project-scaffolding#copying-files ] and pass in a string like and it works:
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: 'app/fonts/**'} );
Unfortunately the files that I need to have no processing performed on are not all in the same directory and I'd like to be able to pass in an array of them, something like the following block of code, but this does not work.
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: ['app/fonts/**', 'app/images/*.png', 'app/images/*.jpg']} );
Any thoughts on how I can have multiple targets for the 'noProcess' option?
As soon as I posted the question, I realized that my proposed code did work. I simply had an invalid path when I'd renamed my 'app' directory to 'dev'.
When I instantiate a Directory in Dart, and that file exists, how can I check whether the Directory is a real folder, or just a symlink?
The way you can recognize a symlink is if the path differs from the full path. Directory doesn't have fullPath() or fullPathSync(), but File.fullPathSync() works on directories. So you can do this:
bool maybeIsSymlink(String path) {
var fullPath = new File(path).fullPathSync();
return path != fullPath;
}
However this only works correctly when path is absolute, and none of its ancestors are symlinks. To work around that you can get the full path of the directory's parent, append the directory name and compare that:
bool isSymlink(String pathString) {
var path = new Path(path);
var parentPath = path.directoryPath;
var fullParentPath = new File.fromPath(parentPath).fullPathSync();
var expectedPath = new Path(fullParentPath).append(path.filename).toString();
var fullPath = new File.fromPath(path).fullPathSync();
return fullPath != expectedPath;
}
Note that I have not tested this, but I've dealt with symlinks a lot in Dart, and this should work. If pathString ends in '/' you'll have to remove it. I usually end up getting paths from a directory listing, so I track the expected path as I recurse down the directory structure.
You can see a special listDirectory() implementation that detects symlinks and sends Symlink instances to the stream along with Files and Directorys in a branch in buildtool: https://github.com/dart-lang/buildtool/blob/m4/lib/src/util/io.dart
In bleeding edge, there now is a static FileSystemEntity.isLinkSync(path) methods that will tell you if something is a symlink; also when it is a broken symlink.
http://api.dartlang.org/docs/bleeding_edge/dart_io/FileSystemEntity.html
For operations on links we are adding a Link class. The code is out for review now:
https://codereview.chromium.org/12691002
If you want to check from the command line to verify what is happening,
ls -al DIRNAME and check for 'l' in the permissions section, and examine what it's pointing "to" on the right side of the output.
see also man 1 stat
If you're wanting to check that from within Dart itself, I don't know how.
FileSystemEntity.typeSync(path)
return an FileSystemEntityType with one of the values
FileSystemEntityType.DIRECTORY
FileSystemEntityType.FILE
FileSystemEntityType.LINK
FileSystemEntityType.NOT_FOUND
I want to get the parent directory path of my solution's startup project, by testing that code
string parent = System.IO.Directory.GetParent(Server.MapPath("~/"));
I get the directory where my solution's startup project is currently placed. Why ?
I am not sure why this happens, at the momemt. But you can do
string parent = new DirectoryInfo(Server.MapPath("~/")).Parent.FullName;
to get the parent directory path.
I try to find a answer why System.IO.Directory.GetParent(Server.MapPath("~/")) does not work and update this if i found something.
Update
I found a possible answer on another Stackoverflow question who GSerg say
I can only assume Directory.GetParent(...) can't assume that C:\parent\child is a directory instead of a file with no file extension. DirectoryInfo can, because you're constructing the object that way.
The reason this is happening is because Server.MapPath is appending a \ at the end of the path (even if you remove it from your MapPath), for example:
C:\foo\bar\
If you try to get the parent directory of that, it will give C:\foo\bar without the slash.
So this will work:
var path = System.IO.Directory.GetParent(Server.MapPath("~").TrimEnd('\\'));
Here is an alternative:
var path = new System.IO.DirectoryInfo(Server.MapPath("~")).Parent.FullName;