'System.NullReferenceException' occurred in opennlp-tools-1.6.0.dll while training NER using OpenNLP - opennlp

I am trying to train NER with OpenNLP and I got System.NullReferenceException in opennlp-tools-1.6.0. Here is the code.
public void Train()
{
Charset charset = Charset.forName("UTF-8");
var lineStream = new PlainTextByLineStream(new FileInputStream(trainingDataFilePath), charset);
var sampleStream = new NameSampleDataStream(lineStream);
TokenNameFinderModel model = null;
try
{
model = NameFinderME.train("en", "medicine", sampleStream, Collections.emptyMap());
BufferedOutputStream modelOut = null;
modelOut = new BufferedOutputStream(new FileOutputStream(onlpModelPath));
}
catch (Exception ex)
{
throw ex;
}
}
Error Message
An exception of type 'System.NullReferenceException' occurred in opennlp-tools-1.6.0.dll but was not handled in user code
StackTrace
at opennlp.tools.ml.maxent.GISTrainer.trainModel(Int32 , DataIndexer , Prior , Int32 , Int32 )
at opennlp.tools.ml.maxent.GIS.trainModel(Int32 iterations, DataIndexer indexer, Boolean printMessagesWhileTraining, Boolean smoothing, Prior modelPrior, Int32 cutoff, Int32 threads)
at opennlp.tools.ml.maxent.GIS.doTrain(DataIndexer indexer)
at opennlp.tools.ml.maxent.GIS.<bridge>doTrain(DataIndexer x0)
at opennlp.tools.ml.AbstractEventTrainer.train(ObjectStream events)
at opennlp.tools.namefind.NameFinderME.train(String languageCode, String type, ObjectStream samples, TrainingParameters trainParams, AdaptiveFeatureGenerator generator, Map resources)
at opennlp.tools.namefind.NameFinderME.train(String languageCode, String type, ObjectStream samples, TrainingParameters trainParams, Byte[] featureGeneratorBytes, Map resources)
at opennlp.tools.namefind.NameFinderME.train(String languageCode, String type, ObjectStream samples, Map resources)
at Notes.Models.OpenNLP.Training.PersonClassifierTraining.Train() in C:\Educational\Notes\Notes\App_Data\Training\PersonClassifierTraining.cs:line 29
at Notes.Controllers.HomeController..ctor() in C:\Educational\Notes\Notes\Controllers\HomeController.cs:line 18

Related

Hive UDF - Generic UDF for all Primitive Type

I am trying to implement the Hive UDF with Parameter and so I am extending GenericUDF class.
The problem is my UDF works find on String Datatype however it throws error if I run on other data types. I want UDF to run regardless of data type.
Would someone please let me know what's wrong with following code.
#Description(name = "Encrypt", value = "Encrypt the Given Column", extended = "SELECT Encrypt('Hello World!', 'Key');")
public class Encrypt extends GenericUDF {
StringObjectInspector key;
StringObjectInspector col;
#Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 2) {
throw new UDFArgumentLengthException("Encrypt only takes 2 arguments: T, String");
}
ObjectInspector keyObject = arguments[1];
ObjectInspector colObject = arguments[0];
if (!(keyObject instanceof StringObjectInspector)) {
throw new UDFArgumentException("Error: Key Type is Not String");
}
this.key = (StringObjectInspector) keyObject;
this.col = (StringObjectInspector) colObject;
return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
}
#Override
public Object evaluate(DeferredObject[] deferredObjects) throws HiveException {
String keyString = key.getPrimitiveJavaObject(deferredObjects[1].get());
String colString = col.getPrimitiveJavaObject(deferredObjects[0].get());
return AES.encrypt(colString, keyString);
}
#Override
public String getDisplayString(String[] strings) {
return null;
}
}
Error
java.lang.ClassCastException: org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaIntObjectInspector cannot be cast to org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector
I would suggest you to replace StringObjectInspector col with PrimitiveObjectInspector col and the corresponding cast this.col = (PrimitiveObjectInspector) colObject. Then there are two ways:
First is to process every possible Primitive type, like this
switch (((PrimitiveTypeInfo) colObject.getTypeInfo()).getPrimitiveCategory()) {
case BYTE:
case SHORT:
case INT:
case LONG:
case TIMESTAMP:
cast_long_type;
case FLOAT:
case DOUBLE:
cast_double_type;
case STRING:
everyting_is_fine;
case DECIMAL:
case BOOLEAN:
throw new UDFArgumentTypeException(0, "Unsupported yet");
default:
throw new UDFArgumentTypeException(0,
"Unsupported type");
}
}
Another way, is to use PrimitiveObjectInspectorUtils.getString method:
Object colObject = col.getPrimitiveJavaObject(deferredObjects[0].get());
String colString = PrimitiveObjectInspectorUtils.getString(colObject, key);
It just pseudocode like examples. Hope it helps.

Exception Devart.Data.Linq on a server "Devart.Data.Oracle.Linq.Provider"

I am trying to deploy my application on Windows server 2007 32 Bit.
My application gave me this Exception
Error on opening DbConnection. bei Devart.Data.Linq.LinqCommandExecutionException.CanThrowLinqCommandExecutionException
(String message, Exception e)
bei Devart.Data.Linq.Provider.k.a.g()
bei Devart.Data.Linq.Provider.k.a.b(IConnectionUser A_0)
bei Devart.Data.Linq.Provider.k.b(IConnectionUser A_0)
bei Devart.Data.Linq.Provider.DataProvider.ExecuteQuery(CompiledQuery compiledQuery, Object[] parentArgs, Object[] userArgs, Object lastResult)
bei Devart.Data.Linq.Provider.DataProvider.ExecuteAllQueries(CompiledQuery compiledQuery, Object[] userArguments)
bei Devart.Data.Linq.Provider.DataProvider.CompiledQuery.Devart.Data.Linq.Provider.ICompiledQuery.Execute(IProvider provider, Object[] userArgs)
bei Devart.Data.Linq.DataQuery`1.i()
bei System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
bei System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
while executing this line in my program
var list = clientCustomers.ToList();
Code
public Repository(String Connection, String EventPackageName, String EventScopeName)
{
this.connectionDict = this.getConnectionInfo(Connection);
//this.context = new DataContext(connection);//old way
this.context = new DataContext(Connection, new Devart.Data.Oracle.Linq.Provider.OracleDataProvider());
this.eventContext = new EventPacDataContext(Connection);
this.eContext = new Context.EventPacDataContext(Connection, new Devart.Data.Oracle.Linq.Provider.OracleDataProvider());
this.eventPackageName = EventPackageName;
this.eventScopeName = EventScopeName;
this.clientUserName = this.connectionDict["User Id"];
}
/// <summary>
/// Collect all Customers from VIEW
/// </summary>
/// <returns>IQueryable<Customer></returns>
public IQueryable<Customer> GetCustomers()
{
try
{
var result = from p in this.context.YDEVQUALIBASICs
join extended in this.context.YDEVQUALIBASICEXTENDEDs on
p.ACCOUNTID equals extended.ACCOUNTID
select
new Customer
{
Base = new Customer
{
CustomerId = p.CUSTOMERID.ToString(),
CustomerNo = p.CUSTOMERNO.ToString(),
Geburtsdatum = p.DETGEBURTSDATUM.GetValueOrDefault(new DateTime(1900, 1, 1)),
Email = p.DETEMAIL,
BusinessArea = p.ACCBUSINESSAREA,
ContractType = p.ACCCONTRACTTYPE,
ContractTariff = p.ACCCONTRACTARIFF,
SubscribeChannel = p.DETANMELDEKANAL,
PaymentMethod = p.CUSCOLLECTIONIDENT,
CustomerAddress = new Address
{
City = p.CUSCITY,
Street = p.CUSSTREET,
ExtendedInfo = p.CUSEHNR,
StreetNumber = p.CUSHNR,
LCountry = p.CUSCOUNTRYL,
SCountry = p.CUSCOUNTRYS,
ZipCode = p.CUSZIPCODE
},
AccountPerson = new Person
{
Salutation = p.ACCANREDE,
Title = p.ACCAKADEM,
Branche = p.ACCBRANCHE,
Lastname = p.ACCTOMERNAME1,
Firstname = p.ACCTOMERNAME2,
Name3 = p.ACCTOMERNAME3
}
},
CustomerPerson = new Person
{
Salutation = p.CUSANREDE,
Title = p.CUSAKADEM,
Branche = p.CUSBRANCHE,
Lastname = p.CUSTOMERNAME1,
Firstname = p.CUSTOMERNAME2,
Name3 = p.CUSTOMERNAME3
},
InternGeolocChecked = extended.DETINTERNGEOLOCCHECKED,
InternGeolocStatus = extended.DETINTERNGEOLOCSTATUS,
};
return result;
}
catch (ReflectionTypeLoadException ex)
{
StringBuilder sb = new StringBuilder();
foreach (Exception exSub in ex.LoaderExceptions)
{
sb.AppendLine(exSub.Message);
if (exSub is FileNotFoundException)
{
FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
{
sb.AppendLine("Fusion Log:");
sb.AppendLine(exFileNotFound.FusionLog);
}
}
sb.AppendLine();
}
string errorMessage = sb.ToString();
//Display or log the error based on your application.
logger.Fatal("Aha: " + errorMessage);
return null;
}
catch (Exception ex)
{
logger.Fatal("Customer failed: " + ex.Message + ex.StackTrace);
throw new DataAccessException("Customer failed", ex);
}
}
When deploying applications written with the help of LinqConnect you should register run-time assemblies Devart.Data.Oracle.dll, Devart.Data.dll, Devart.Data.Oracle.Linq.dll and Devart.Data.Linq.dll at Global Assembly Cache (GAC) or place them in the folder of your application.
When deploying ASP.NET applications it is also necessary to have Devart.Data.Oracle.Web.dll and App_Licenses.dll assemblies available.
If all required assemblies are available for your project, please perform the following steps:
Make sure that Oracle Client Software is installed on your computer;
Specify the name of Oracle Home explicitly in the Home connection string parameter.
Place the content of the ORACLE_HOME variable on the first position in the PATH variable of your operating system;
Make sure that capacity (x86 or x64) of your application and the capacity of your Oracle Client are the same.
If after these steps the issue still persists, please contact us with more details for this issue, e.g.:
the full stack trace of the exception;
the connection string;
the version of the Oracle Client;
the version of the Oracle server;
the definitions of the database tables and corresponding entity classes, etc.

android: how to convert gps coordinates and send it to mysql server using post method

I'm trying to send data in my php server, but the data is in latitude and longitude format.
Here's the error: Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
private class sendlocation extends AsyncTask<String,String,String>
{
#Override
protected String doInBackground(String... args0)
{
double latlat = gps.getLatitude();
double longlong = gps.getLongitude();
String resultlat = Double.toString(latlat);
String resultlong = Double.toString(longlong);
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("Latitude",resultlat));
params.add(new BasicNameValuePair("Longitude",resultlong));
JSONObject json = jsonParser.makeHttpRequest(url_send_loc,"POST", params);
Log.d("Create Response", json.toString());
try
{
int success = json.getInt(TAG_SUCCESS);
if(success == 1)
{
Toast.makeText(getApplicationContext(),"Location Successfully sent: \nLat "+resultlat+" nLong" + resultlong ,Toast.LENGTH_LONG).show();
}
else
{ pdialog.dismiss();
Toast.makeText(getApplicationContext(), "Unknown error! Location not sent", Toast.LENGTH_LONG).show();
}
}catch(JSONException e)
{
e.printStackTrace();
}
return null;
};
}

how to upload an image using servlet to an absolute path

I want to upload a file to my project folder. My code is as follows:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
File savedFile;
String destination;
List<FileItem> items = null;
try {
items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
} else {
// Process form file field (input type="file").
String fieldName = item.getFieldName();
String fileName = FilenameUtils.getName(item.getName());
InputStream fileContent = item.getInputStream();
String userName = (String) session.getAttribute("newUser");
destination = getServletConfig().getServletContext().getContextPath() + "\\" + userName + ".jpeg";
savedFile = new File(destination);
//Check if file exists
if(!savedFile.exists())
savedFile.createNewFile();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(savedFile));
byte[] buffer = new byte[1024];
int len;
//Read from file and write to new file destination
while((len = fileContent.read(buffer)) >= 0) {
bos.write(buffer, 0, len);
}
//Closing the streams
fileContent.close();
bos.close();
}
}
}
When I run the jsp file and browse and select the required image and submit the form, the servlet runs but it throws IOException. The exception is throws by the line where I create a new path using savedFile.createNewFile(). Before I used that code, it threw another FileNotFoundException. I am not sure if the path that I have provided is correct.
Try to use getRealPath() method.
String fileName="/" + userName + ".jpeg";
destination = getServletContext().getRealPath(fileName);
savedFile = new File(destination);

Internal Error: Image is a collection image,expecting ADT with Oracle

I am trying to call a stored function on an oracle database with spring-jdbc.
This is the stored function I am trying to call:
FUNCTION GET_RESOURCE_LIST RETURN RESOURCE_TAB;
Next is the definition of resource_tab
TYPE RESOURCE_TAB AS TABLE OF TRESOURCE;
Next is the definition of tresource
TYPE TRESOURCE AS OBJECT(
RESOURCE_ID NUMBER(10,0),
RESOURCE_NAME VARCHAR2(100)
)
The calling code
final SimpleJdbcCall call = new SimpleJdbcCall(idmJdbcTemplate).withFunctionName("get_resource_list").declareParameters(new SqlOutParameter(
"RETURN", OracleTypes.STRUCT,
"RESOURCE_TAB",
new SqlReturnType() {
#Override
public Object getTypeValue(CallableStatement cs, int paramIndex, int sqlType, String typeName) throws SQLException {
final Struct s = (Struct)cs.getObject(paramIndex);
final Object[] attr = s.getAttributes();
return attr[1];
}
}));
call.compile();
final Collection<String> resources = call.executeFunction(Collection.class);
Last is the stack trace that I am receiving:
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call WVUID.IDM_REPO_MANUAL.GET_RESOURCE_LIST()}]; SQL state [99999]; error code [17001]; Internal Error: Image is a collection image,expecting ADT; nested exception is java.sql.SQLException: Internal Error: Image is a collection image,expecting ADT
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:969)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
Truncated. see log file for complete stacktrace
Caused By: java.sql.SQLException: Internal Error: Image is a collection image,expecting ADT
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
Truncated. see log file for complete stacktrace
>
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1015)
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:953)
... 62 more
I have the same problem, and I spent a day to fix it.
Thinking about error "Image is a collection image", instead of
OracleTypes.STRUCT it must be OracleTypes.ARRAY.
About your getTypeValue(...) method I can't say is it right or not, but I will show how parse the resultset (maybe it is and other way, please write it):
#Override
public Object getTypeValue(CallableStatement cs, int paramIndex,
int sqlType, String typeName) throws SQLException {
ARRAY struct = (ARRAY) cs.getObject(paramIndex);
ResultSet rs = struct.getResultSet();
while (rs.next()) {
Object rowIndex = rs.getObject(1);
oracle.sql.STRUCT row = (oracle.sql.STRUCT) rs.getObject(2);
if (row != null) {
Object[] cols = row.getAttributes();
System.out.print(rowIndex + ": ");
for (Object col : cols) {
System.out.print(col + " ");
}
System.out.println();
}
}
return "construct your data structure above and return here";
}
the another way is
#Override
public Object getTypeValue(CallableStatement cs, int paramIndex,
int sqlType, String typeName) throws SQLException {
ARRAY array = (ARRAY) cs.getObject(paramIndex);
Object[] rows = (Object[])array.getArray();
for(Object row : rows){
Object[] cols = ((oracle.sql.STRUCT)row).getAttributes();
for (Object col : cols) {
System.out.print(col + " ");
}
System.out.println();
}
return "construct your data structure above and return here";
}
The problem is with the declaration of the output parameter
final SimpleJdbcCall call = new SimpleJdbcCall(idmJdbcTemplate).withFunctionName("get_resource_list").declareParameters(new SqlOutParameter(
"RETURN", OracleTypes.STRUCT,
"RESOURCE_TAB",
new SqlReturnType() <etc>
The return type (TYPE RESOURCE_TAB AS TABLE OF TRESOURCE) is not a OracleTypes.STRUCT (that is reserved for Object Types) but an OracleTypes.ARRAY.

Resources