Stanford Lexicalized Parser Load Model error - stanford-nlp

I am using the NLP Parser on C# under visual studio 2012.
NuGet installed fine, can compile the simple example.
I have noticed an issue with the model loader:
try
{
System.Console.WriteLine(System.IO.File.Exists(full) ? "File exists." : "File does not exist.");
LexicalizedParser lp = LexicalizedParser.loadModel(full);
lp.setOptionFlags(new String[] { "-maxLength", "80", "-retainTmpSubcategories" });
//if (!String.IsNullOrEmpty(fileName))
//DemoDP(lp, fileName);
//else
DemoAPI(lp);
}
catch (Exception e)
{
System.Console.WriteLine(e.Message);
throw e;
}
I get some sort of file reading formatting error:
C:\NLPTest\bin\x86\Debug\englishPCFG.ser.gz: expecting BEGIN block; got ??
The model file is about 8 MB, but I don't have a clue about the format of this model file.
Is there somewhere an official file I can download that is sure to be working?

Right I have found the issue, as suspected it was due to the old format of the model.
The way I did it solve it was :
download the project files version 2013
open the jar filed called stanford-parser-3.2.0-models
extract the englishPCFG.ser.gz
pronounce abracadabra and no more format error
Hope it helps other people!

Related

FilePicker class cannot be found in Xamarin project

I'm creating a Xamarin forms app which enables user uploads. I have installed the latest version of the Xamarin.Essentials package but the classes and methods which I would expect to be available cannot be found. I can move ahead with the xamarin.plugins.filepicker package but this is not well documented and I would prefer to use the standard library. Any assistance with this would be greatly appreciated! The default is below.
'''
async Task<FileResult> PickAndShow(PickOptions options)
{
try
{
var result = await FilePicker.PickAsync();
if (result != null)
{
Text = $"File Name: {result.FileName}";
if (result.FileName.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) ||
result.FileName.EndsWith("png", StringComparison.OrdinalIgnoreCase))
{
var stream = await result.OpenReadAsync();
Image = ImageSource.FromStream(() => stream);
}
}
}
catch (Exception ex)
{
// The user canceled or something went wrong
}
}
'''
For the Xamarin.Essentials package, update to the latest version on both Xamarin.Form NuGet Package and Android NuGet Package. After that you could fix the errors like below.
Error CS0246 The type or namespace name 'PickOptions' could not be found (are you
missing a using directive or an assembly reference?)
For the usage of Xamarin.Essentials: File Picker, you could check the MS document.
https://learn.microsoft.com/en-us/xamarin/essentials/file-picker?tabs=android
If you wanna the source file, you could download from the link below. https://github.com/xamarin/Essentials/tree/main/Xamarin.Essentials/FilePicker

Open Uri to read JSON file in background task UWP

I have a use case where I have to read a config.json file from an AppService and based on the configuration in json file I have to generate an ID.
I am using following piece of code to generate the Uri so that I can open the file using StorageFile.GetFileFromApplicationUriAsync(fileUri).
Uri fileUri = null;
try
{
Debug.WriteLine("Creating new uri");
fileUri = new Uri(fileName);
if (fileUri == null)
{
Debug.WriteLine("Uri creation failed");
} else
{
Debug.WriteLine("New Uri created");
}
} catch (Exception ex)
{
Debug.WriteLine("Uri creation failed" + ex.Message);
}
Now when I am trying to debug this code my debugger is disappearing after line with new Uri(fileName)
If I just let the code run with no breakpoints I am not seeing any message after Creating new uri. Not even an exception.
Value of fileName is "ms-appx:///config/config.json"
Can anyone please explain what is wrong here? Also is it possible to open and read a file from an AppService?
--
Thanks
Tarun
The uri use appx only can read the resource is content in msbuild.
You can right click the file and select the property and you should select the file's build action as content.
http://jycloud.9uads.com/web/GetObject.aspx?filekey=449e34647d61faca2ce846b773a4da8e
http://jycloud.9uads.com/web/GetObject.aspx?filekey=5423b79037eee8dc66431d0478d79871
http://jycloud.9uads.com/web/GetObject.aspx?filekey=6189eb9547c6f2fa79333df67ab33cef
You can see the last image is use complie and you can change it to content.
Sorry, my visual studio's language is local language.But the visual studio's have the same layout.

how to programmatically kick off a ssis package in asp.net MVC3 to import excel files

I am having some trouble with a asp.net MVC3 web application that I am developing. I need an upload page which Allows the user to upload excel files and dump them to the file system. I got this to work fine. The next part is the part that I am having trouble with, After I upload the excel files I need to programmatically kick off a SSIS package which I have created already to import the excel files.
Here is what I have so far in code:
//
// POST: /Home/Update/
[HttpPost]
public ActionResult Update(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
ViewBag.Message = "File Uploaded Successfully";
file.SaveAs(path);
}
//Start the SSIS here
try
{
Application app = new Application();
Package package = null;
package = app.LoadPackage( #"C:\Users\Chris\Documents\Visual Studio
2008\Projects\Integration Services Project1\Integration Services Project1
\bin\Package.dtsx", null);
// Execute Package
DTSExecResult results = package.Execute();
if(results == DTSExecResult.Failure)
{
foreach(DtsError local_DtsError in package.Errors)
{
ViewBag.Message("Package Execution results:{0}",
local_DtsError.Description.ToString());
}
}
}
catch(DtsException ex)
{
//ViewBag.Message("{0} Exception caught.", ex);
}
// redirect back to the index action to show the form once again
return RedirectToAction("Update");
}
When I run the code and upload an excel file I get a DtsException caught, which says:
Failed to open package file "C:\Users\Chris\Documents\Visual Studio 2008\Projects\Integration Services Project1\Integration Services Project1\bin\Package.dtsx" due to error 0x80070003 "The system cannot find the path specified.". This happens when loading a package and the file cannot be opened or loaded correctly into the XML document. This can be the result of either providing an incorrect file name was specified when calling LoadPackage or the XML file was specified and has an incorrect format.
I don't understand why it is giving me this because the file path is right I checked and it is exactly correct. I need some help fixing this issue I would greatly appreciate any help you guys can give.
Permissions I should think. Put the file somewhere where account running IIS can see it. Whereever you were planning on deploying it, would be good.

Eclipse RCP XMLMultiPageEditorPart errors

all
When I use XMLMultiPageEditorPart, it makes some errors.
File file = new File(path);
IEditorInput input = new XMLPInput(file);
try {
page.openEditor(input, "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart");
} catch (PartInitException e) {
MessageDialog.openError(window.getShell(), "", path);
}
Errors:
org.eclipse.ui.PartInitException: Text
editor does not have a document
provider at
org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3075)
at
org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3088)
at
org.eclipse.wst.sse.ui.StructuredTextEditor.init(StructuredTextEditor.java:2553)
at
org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:237)
at
org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:211)
I think XMLMultiPageEditorPart should has its own provider? could anyone help me ?
Where did you get the class XMLPInput from? As you are using File, why can't you use the standard FiledEditorInput or FileStoreEditorInput?

IsolatedFileStorage XML Reading Crash

Ok so, basically my problem is with reading and XML file from IsolatedFileStorage. I'll go through the process that leads to my error and then I'll list the relevant code and XML file.
On the first execution it recognises that the file does not exist - it therefore creates the file in IsolatedFileStorage
On the second execution it can now see that the file does exist and so it loads the XML file
On the third execution it can see that it exists - but it throws an XML error
I cannot for the life of me find a solution to it (link to other discussion on MSDN here)
So the code for reading/creating the XML file in IsolatedFileStorage is as follows:
try
{
/***********************
* CHECK THE SETTINGS
********************/
if (store.FileExists("AppSettings.xml"))
{
streamSettings = new IsolatedStorageFileStream("AppSettings.xml", System.IO.FileMode.Open, store);
DebugHelp.Text = "AppSettings.xml exists... Loading!";
streamSettings.Seek(0, System.IO.SeekOrigin.Begin);
xmlDoc = XDocument.Load(streamSettings, LoadOptions.None);
}
else
{
streamSettings = new IsolatedStorageFileStream("AppSettings.xml", System.IO.FileMode.Create, store);
DebugHelp.Text = "AppSettings.xml does not exist... Creating!";
xmlDoc = XDocument.Load("AppSettings.xml", LoadOptions.None);
}
if (xmlDoc != null)
xmlDoc.Save(streamSettings);
}
catch (Exception e)
{
DebugHelp.Text = e.ToString();
}
finally
{
streamSettings.Close();
}
And the related XML file is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<Settings>
</Settings>
Extremely advanced I know - however it throws the following error (here) and you can find the full error text at the bottom of the Social.MSDN page.
Please help - I have been looking for a solution (as the one on the social.msdn site didn't work) for about 2 weeks now.
Why don't you try to read file using a simple StreamReader ? Below a part of a method I have created to readfile from store. Have a try, check your content, and then try loading xml from String (XDocument.Parse etc ...)
String fileContent = String.Empty;
using (_store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (_store.FileExists(file))
{
_storeStream = new IsolatedStorageFileStream(file, FileMode.Open, _store);
using (StreamReader sr = new StreamReader(_storeStream))
{
fileContent = sr.ReadToEnd();
}
__storeStream.Close();
return fileContent;
}
else {
return null;
}
}
It looks to me like the problem is in your save method - it looks like you are maybe appending the settings each time you close - to overwrite your existing settings, you need to ensure that you delete your existing file and create a new one.
To help debug this, try using http://wp7explorer.codeplex.com/ - this might help you see the raw file "on disk"
As an aside, for settings in general, do check out the AppSettings that IsolatedStorage provides by default - unless you have complicated needs, then these may suffice on their own.
Your code sample isn't complete so it's hard to say for sure but, rather than just seeking to the start of the file you may find it easier to just delete it if it already exists. You can do this with FileMode.Create. In turn this means you can do away with the need to check for the existing file.
I suspect that the problem is that you are writing a smaller amount of text to the file on subsequent attempts and so leaving part of the original/previous text behind. In turn this creates a file which contains invalid XML.

Resources