Wednesday, January 30, 2013

Loading a file into Jena

Ok, so I got so many exceptions like:

com.hp.hpl.jena.shared.DoesNotExistException
com.hp.hpl.jena.shared.JenaException: java.net.UnknownHostException:
com.hp.hpl.jena.shared.JenaException: java.net.MalformedURLException: no protocol

First of all, you need to give a URL of file, not a path to file, to Jena. Second, at some cases, like mine, just adding the string "file:" or "file://" to the beginning of your file address doesn't work. BUT, getting the file's URI and converting it to String works perfectly, even though it returns the same string as if you have appended the file address with "file:".

So, if you're struggling over reading some files into Jena, as I did, give this a try:

String url = new File(fileAddr).toURI().toString();
TDBLoader.loadModel(model, url, true);

Sunday, January 20, 2013

MSE of Non-Zero Elements in Matlab


Suppose you have a predicted matrix and a ground truth matrix. You want to find MSE (Mean Squared Error) of only non-zero elements in your prediction. Here is what you do:

[i j k]= find(truth);

f = (sparse(i,j,k)-sparse(i,j,predicted(find(truth)))).^2;

MSE=sum(f,2)./sum(f~=0,2);



The following counts (size of) the nonzero entries in each row of a matrix without loop:

c = sum(f~=0,2);


spconvert does the reverse of full command :)

Tuesday, January 8, 2013

Setting Group Permission of a Folder in Linux


make sure user is in the group:
sudo usermod -a -G <group-_name> <some_user>

set the correct permissions on group:
sudo chgrp -R <group-_name> <folder>
sudo chmod -R g+w <folder>

make sure all new files and directories created under <folder> are owned by the group:
sudo find <folder> -type d -exec chmod 2775 {} \;  


Find all files in <folder> and add read and write permission for owner and group:



sudo find <folder> -type f -exec chmod ug+rw {} \;