Mahout MySQLBooleanPrefJDBCDataModel issue - mahout-recommender

I am trying to generate recommendation on a table having no preference value but it always gives error like "DataModel doesn't have preference values".
I have created Boolean datamodel as shown below why it is giving this error.Please help me to resolve this issue.I am attaching code for my database connection and datamodel creation as below.
MysqlDataSource dataSource = new MysqlDataSource ();
dataSource.setServerName("localhost");
dataSource.setUser("root");
dataSource.setPassword("******");
dataSource.setDatabaseName("recommendation");
MySQLBooleanPrefJDBCDataModel dataModel = new MySQLBooleanPrefJDBCDataModel(dataSource,"test","user_id","song_id", null);
I followed this link https://stackoverflow.com/questions/23537322/how-to-make-a-more-efficient-recommender-in-mahout but faced same problem

Related

Grails 3 Entity not saved when properties set in EntityClass

I occure a problem which I do not understand. Following code does not work:
AccountingEntity accountingEntity = AccountingEntity.get(params.id);
accountingEntity.setLifecycleStatusToArchived();
accountingEntity.save(flush:true);
Where the method setLivecylceStatusToArchived looks like:
void setLifecycleStatusToArchived() {
this.lifecycleStatus = AccountingEntity.LIFECYCLE_ARCHIVED; //predefined static variable
this.considerForRankingJob = false;
this.dateArchived = new Date();
}
Problem is, that the entity is not updated.
No validation erros when I use accountingEntity.validate() in advance.
However, this code works:
AccountingEntity accountingEntity = AccountingEntity.get(params.id);
accountingEntity.setDateArchived(new Date());
accountingEntity.setConsiderForRankingJob(false);
accountingEntity.setLifecycleStatus(AccountingEntity.LIFECYCLE_ARCHIVED);
accountingEntity.save(flush:true);
The code did not work any more after update from Grails 3.2.9 to 3.3.0.RC1 (Gorm 6.1.5) unless I followed all the steps in the guide (http://docs.grails.org/3.3.x/guide/upgrading.html) and the rest of the code is working properly (also database accesses etc.)
Has anybody an idea? What the problem could be?
Thanks in advance and best regards!
The short answer is dirty checking. When you are setting properties inside the instance method Grails doesn't know they are dirty.
See the following github issue for how to resolve the problem:
https://github.com/grails/grails-data-mapping/issues/961
you have 2 options:
call markDirty every time you change an internal field. This will be
better for performance or as per
http://gorm.grails.org/latest/hibernate/manual/index.html#upgradeNotes
use
hibernateDirtyChecking: true

MVC5 with ReportViewerForMvc

I am designing an MVC application using ReportViewerForMVC. This is my controller code:
ReportViewer rp = new ReportViewer();
rp.ProcessingMode = ProcessingMode.Local;
rp.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath)
+ #"Report/sampleFile.rdlc";
ViewBag.ReportViewer = rp;
This is my View:
#using ReportViewerForMvc
#Html.ReportViewer(ViewBag.ReportViewerMicrosoft.Reporting.WebForms.ReportViewer)
The iframe shows but i get this message:
A data source instance has not been supplied for the data source 'DataSet1'.
as my output for the report section. I thought i specified my data source when designing my .rdlc file.
Again, i want to ask if i create a datatable with a where clause having parameter, how can i specify the value in my controller.
I have searched online and i'm not getting any useful. Can anyone please help me out?
The report viewer has no DataSource. If you like using designer view like myself, you could start by creating a dataset and adding a dataAdapter which will automatically add a dataTable. The dataSource can be set like this:
DataSet1 ds = new DataSet1();
TableAdapter1 ta = new TableAdapter1();
ta.Fill(ds.Table[0]);
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet";
rds.Value = ds.Table[0];
rp.LocalReport.DataSources.Clear();
rp.LocalReport.DataSources.Add(rds);
rp.LocalReport.Refresh();
As simple as that...
Change the following in View
#Html.ReportViewer(ViewBag.ReportViewerMicrosoft.Reporting.WebForms.ReportViewer)
to
#Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)

EF5 need update ContainerName.FunctionImportName for accessing Stored Procedure when updating models, Any charming solution?

I'm new to entity framework, please forgive me if my question is too simple.
I'm using EF5 build my project at the moment, there is one Function Import "GetStockItem" in my project, which calls a stored procedure and returns data from SP. Every time when I "Update Model from database" from Model Diagram, the update wizard reflects the changes of database without problem, but GetStockItem stops working. The error message when I call GetStockItem is:
"The value of EntityCommand.CommandText is not valid for a StoredProcedure command. The EntityCommand.CommandText value must be of the form 'ContainerName.FunctionImportName'."
The solution, as instructed in the error message is clear, all I need is to add ContainerName. before the FunctionImportName (GetStockItem in my case) in the context.cs file.
My question is how can I avoid the from happening every time when I update models from database? It's quite annoying to do this manual thing now and then, and it's easy to forget to do this then cause users' complaint.
Hope someone can enlighten me with charming solution! Cheers!
I just ran into this using EF5/DbContext. The solution I found was to edit the T4 template ([Model].Context.tt) that generates the DbContext.
In this file, locate the instructions for generating the ExecuteFunction call. For me, it started on line 288:
public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
{
var parameters = _typeMapper.GetParameters(edmFunction);
var returnType = _typeMapper.GetReturnType(edmFunction);
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
if (includeMergeOption)
{
callParams = ", mergeOption" + callParams;
}
return string.Format(
CultureInfo.InvariantCulture,
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});",
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
edmFunction.Name,
callParams);
}
Modify the return line so that edmFunction.Name is replaced with edmFunction.FullName and upon saving, the Function Import code will be regenerated using fully-qualified names.
I had a similar issue, I suggest not to change the context.cs file at all; only make sure the connection strings in app.config file generated by EF is the same in the calling project, especially the metadata that in the connection string is very important to be correct. If it helps, please mark this answer accepted otherwise send me the steps to reproduce this error.

Corrupting Access databases when inserting values

Recently, a program that creates an Access db (a requirement of our downstream partner), adds a table with all memo columns, and then inserts a bunch of records stopped working. Oddly, there were no changes in the environment that I could see and nothing in any diffs that could have affected it. Furthermore, this repros on any machine I've tried, whether it has Office or not and if it has Office, whether it's 32- or 64-bit.
The problem is that when you open the db after the program runs, the destination table is empty and instead there's a MSysCompactError table with a bunch of rows.
Here's the distilled code:
var connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=corrupt.mdb;Jet OLEDB:Engine Type=5";
// create the db and make a table
var cat = new ADOX.Catalog();
try
{
cat.Create(connectionString);
var tbl = new ADOX.Table();
try
{
tbl.Name = "tbl";
tbl.Columns.Append("a", ADOX.DataTypeEnum.adLongVarWChar);
cat.Tables.Append(tbl);
}
finally
{
Marshal.ReleaseComObject(tbl);
}
}
finally
{
cat.ActiveConnection.Close();
Marshal.ReleaseComObject(cat);
}
using (var connection = new OleDbConnection(connectionString))
{
connection.Open();
// insert a value
using (var cmd = new OleDbCommand("INSERT INTO [tbl] VALUES ( 'x' )", connection))
cmd.ExecuteNonQuery();
}
Here are a couple of workarounds I've stumbled into:
If you insert a breakpoint between creating the table and inserting the value (line 28 above), and you open the mdb with Access and close it again, then when the app continues it will not corrupt the database.
Changing the engine type from 5 to 4 (line 1) will create an uncorrupted mdb. You end up with an obsolete mdb version but the table has values and there's no MSysCompactError. Note that I've tried creating a database this way and then upgrading it to 5 programmatically at the end with no luck. I end up with a corrupt db in the newest version.
If you change from memo to text fields by changing the adLongVarWChar on line 13 to adVarWChar, then the database isn't corrupt. You end up with text fields in the db instead of memo, though.
A final note: in my travels, I've seen that MSysCompactError is related to compacting the database, but I'm not doing anything explicit to make the db compact.
Any ideas?
As I replied to HasUp:
According MS support, creation of Jet databases programmatically is deprecated. I ended up checking in an empty model database and then copying it whenever I needed a new one. See http://support.microsoft.com/kb/318559 for more info.

db4o issue with graph of objects

I am a new to db4o. I have a big problem with persistance of a graph of objects. I am trying to migrate from old persistance component to new, using db4o.
Before I peristed all objects its graph looked like below (Take a look at Zrodlo.Metadane.abstrakt string field with focused value) [its view from eclipse debuger] with a code:
ObjectContainer db=Db4o.openFile(DB_FILE);
try {
db.store(encja);
db.commit();
} finally{
db.close();
}
After that, I tried to read it with a code:
ObjectContainer db=Db4o.openFile((DB_FILE));
try{
Query q = db.query();
q.constrain(EncjaDanych.class);
ObjectSet<Object> objectSet = q.execute();
logger.debug("objectSet.size" + objectSet.size());
EncjaDanych encja = (EncjaDanych) objectSet.get(0);
logger.debug("ENCJA" + encja.toString());
return encja;
}finally{
db.close();
}
and I got it (picture below) - string field "abstrakt" is null now !!!
I take a look at it using ObjectManager (picture below) and abstrakt field has not-null value there!!! The same value, that on the 1st picture.
Please help me :) It is my second day with db4o. Thanks in advance!
I am attaching some code with structure of persisted class:
public class EncjaDanych{
Map mapaIdRepo = new HashMap();
public Map mapaNazwaRepo = new HashMap(); }
!!!!!!!!UPDATED:
When I tried to read only Metadane object (there was only one such a object), it is all right - it's string field abstrakt could be read correctly.
try{
Query q = db.query();
q.constrain(Metadane.class);
ObjectSet<Object> objectSet = q.execute();
logger.error("objectSet.size" + objectSet.size());
Metadane meta = (Metadane) objectSet.get(0);
logger.debu("Metadane" + meta.toString());
return meta;
}finally{
db.close();
}
This is a common db4o FAQ, an issue with what db4o calls "activation". db4o won't instantiate the entire graph you stored when you load an object from an ObjectContainer. By default, objects are instantiated to depth 5. You can change the default configuration to a higher value, but that is not recommended since it will slow down object loading in principle because the depth will be used everywhere you load an object with a query.
Two approaches are possible to solve your issue:
(1) You can activate an object to a desired depth by hand when you need a specific depth.
db.activate(encja, 10) // 10 is arbitrary
(2) You can work with Transparent Activation. There are multiple chapters on how to use Transparent Activation (TA) in the db4o tutorial and in the reference documentation.
You're not setting a filter in your query so you're reading the first object. Are you sure you didn't have a previous object in the database?

Resources