Convert CSV to ARFF using IKVM and WEKA - csv

CSVLoader loader = new CSVLoader();
loader.setSource(new File("));
Instances data = loader.getDataSet();
When i run above code in java , it's working fine.
But when i do the same thing in c# using the following code, it throws exception in line
weka.core.Instances instsOrg = csvLoader.getDataSet();
The exception message is" The type initializer for 'weka.core.converters.ConverterUtils' threw an exception"
string filename = "myCSVfile.csv"";
weka.core.converters.CSVLoader csvLoader = new weka.core.converters.CSVLoader();
csvLoader.setSource(new java.io.File(filename));
weka.core.Instances instsOrg = csvLoader.getDataSet();
weka.core.converters.ArffSaver saver = new weka.core.converters.ArffSaver();
saver.setInstances(data);
saver.setFile(new File("myCSVfile.arff"));
saver.writeBatch();
I have added weka.dll , IKVM.OpenJDK.Core.dll and IKVM.Runtime as references files.
Can anyone help me to get rid of this exception please???
Please reply as soon as possible :(

Related

OutOfMemoryException while extracting OBJ

I have a Revit file and I am trying to extract geometry of it (OBJ file)(master view activated as I need space volumes)
I am calling GetDerivativeManifestAsync method from DerivativesApi class from Autodesk.Forge
await derivative.GetDerivativeManifestAsync(urn, derivativeUrn);
However I am getting System.OutOfMemoryException thrown from forge client.
Reason: Autodesk.Forge.Client.ApiException: Error calling GetDerivativeManifest: Exception of type 'System.OutOfMemoryException' was thrown.
Why does it happen and how can I solve it?
Thank you
It might mean that the OBJ file is too large for your computer to handle. Please use this API of Forge Dotnet SDK to check the file size:
IDictionary<string, string> headers = derivative.GetDerivativeManifestHeaders(urn, derivativeUrn);
long fileSize = Convert.ToInt32(headers["Content-Length"]);
Console.WriteLine ("\t size: " + fileSize); //!<<< in bytes

Import csv file in drf

I'm trying to create a view to import a csv using drf and django-import-export.
My example (I'm doing baby steps and debugging to learn):
class ImportMyExampleView(APIView):
parser_classes = (FileUploadParser, )
def post(self, request, filename, format=None):
person_resource = PersonResource()
dataset = Dataset()
new_persons = request.data['file']
imported_data = dataset.load(new_persons.read())
return Response("Ok - Babysteps")
But I get this error (using postman):
Tablib has no format 'None' or it is not registered.
Changing to imported_data = Dataset().load(new_persons.read().decode(), format='csv', headers=False) I get this new error:
InvalidDimensions at /v1/myupload/test_import.csv
No exception message supplied
Does anyone have any tips or can indicate a reference? I'm following this site, but I'm having to "translate" to drf.
Starting with baby steps is a great idea. I would suggest get a standalone script working first so that you can check the file can be read and imported.
If you can set breakpoints and step into the django-import-export source, this will save you a lot of time in understanding what's going on.
A sample test function (based on the example app):
def test_import():
with open('./books-sample.csv', 'r') as fh:
dataset = Dataset().load(fh)
book_resource = BookResource()
result = book_resource.import_data(dataset, raise_errors=True)
print(result.totals)
You can adapt this so that you import your own data. Once this works OK then you can integrate it with your post() function.
I recommend getting the example app running because it will demonstrate how imports work.
InvalidDimensions means that the dataset you're trying to load doesn't match the format expected by Dataset. Try removing the headers=False arg or explicitly declare the headers (headers=['h1', 'h2', 'h3'] - swap in the correct names for your headers).

Examining the Windows Store apps AppxManifest at Runtime

I try to load the AppxManifest at Runtime to read out the Version of the app. I fond this article:
http://tonychampion.net/blog/index.php/2013/01/examining-the-windows-store-apps-appxmanifest-at-runtime/#comments
I tried the line from the post:
var doc = XDocument.Load("AppxManifest.xml", LoadOptions.None);
But this will throw me the following exception:
{System.Xml.XmlException: An internal error has occurred.
at System.Xml.XmlXapResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.FinishInitUriString()
at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
at MyMedi.Src.Utilities.GetVersion()
at MyMedi.WindowsPhone.Test.Src.UtilitiesTest.Utilities_GetVersionTest()}
Can anyone tell me what I'm doing wrong?
Thanks
NPadrutt
I'm not sure why you'd want to, but you could try loading the document with the ms-appx:// uri schema in the file reference.
There's a much easier way to achieve your goal, though.
Package package = Package.Current;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;
var versionString = string.Format(
CultureInfo.InvariantCulture,
"{0}.{1}.{2}.{3}",
version.Major,
version.Minor,
version.Build,
version.Revision);

How to catch an elusive loader error in AS3

I'm trying to get some data from a php script using a loader and VARIABLES data format. Here's the code I have:
myUrlResults = new URLRequest("http://[...]/getData.php");
myUrlResults.method = URLRequestMethod.GET;
myResultsLoader = new URLLoader();
myResultsLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myResultsLoader.addEventListener(Event.COMPLETE, sendEventCompleteHandler);
myResultsLoader.addEventListener(IOErrorEvent.IO_ERROR, sendEventErrorHandler);
myResultsLoader.load(myUrlResults);
And
function sendEventCompleteHandler(e:Event) {
trace('Ok.');
}
function sendEventErrorHandler(e:IOErrorEvent) {
trace('Error occured:' + e);
}
As you know, Flash gives you a nasty error if the php file is not formatted properly.
But my .php file returns something like this var1=5&var2=10 and everything works great. However, sometimes, the server has issues and returns "Too many connections." which is something Flash doesn't like, because it's not a variable - value pair and I get an error like this:
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables$iinit()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
How to catch this error??
try set
myResultsLoader.dataFormat = URLLoaderDataFormat.TEXT;
and in your complete handler get the variables yourself after verify the result.
You can use a URLVariable.decode() and try/catch it there.

Json: the remote server returned an error (500) internal server error

i am trying to read a web service in Json format
here is my code:
WebClient wc = new WebClient();
wc.UseDefaultCredentials = true;
var data = wc.DownloadString(JsonUri);
MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(data));
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<PaymentMethod>));
var result = serializer.ReadObject(ms);
ms.Close();
ms.Dispose();
i get an error on this line:
var data = wc.DownloadString(JsonUri);
the JsonUri is : http://avaris.kwekud.com/api/v1/items/uniqueitem/?username=joel&api_key=959dd41efd06b84ca7f10b1b12f5f3e6567c07dc&format=json
Any Help
thanks
It looks like there is a problem in the python code on the server that is returning the API. A good idea is to try to make the call from outside of your code to make sure that it is not your code. Any packet sniffing tool eg firebug in firefox will be able to tell you if the call is going wrong pr its your code being badly formed.
It looks like the API is currently broken, so you should put a try ... catch in there and handle the exception for situations like this: