I like to load my EMFText model in a standalone java applicatio - dsl

I have been looking for a possible answer but nothing yet. I found this piece of code but for Xtext
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.getResource(
URI.createURI("platform:/resource/org.xtext.example.mydsl/src/example.mydsl"), true);
Model model = (Model) resource.getContents().get(0);
I need to do exactly the same but using EMFText instead of Xtext. Is that possible?
I would really appreciate any help or answer.
Best regards.

Try this:
new MydslMetaInformation().registerResourceFactory();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.getResource(URI.createFileURI("example.mydsl"), true);
Model model = (Model) resource.getContents().get(0);

Related

How to create a custom model with my own entities

I have been trying to find some reference material on how to create custom models with my own entities , like if I want to recognize the name of sports from a text.How do I do it?
The tools from stanford usually work pretty good for several NLP tasks, but in my experience, training your own models is a lot easier in opennlp. If that's an option for you (you tagged your question "stanford-nlp", but maybe you're not restricted to using only that), you can find some pretty good documentation here: https://opennlp.apache.org/documentation/1.5.3/manual/opennlp.html#tools.namefind.training.tool
try {
propFile = new File(System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/propfile.prop");
properties = new Properties();
properties.load(new FileInputStream(propFile));
String to = properties.getProperty("serializeTo");
properties.setProperty("serializeTo", "ner-customModel.ser.gz");
properties.setProperty("trainFile",System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/outputTokenized.tsv");
CRFClassifier crf = new CRFClassifier(properties);
crf.train();
String s2 = "apples are apples";
System.out.println(crf.classifyToString(s2));
crf.serializeClassifier(System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/ner-customModel.ser.gz");
} catch (IOException e) {
e.printStackTrace();
}
and declare the training file and other properties in the properties file.
This worked for me :)

Create post entity to crm

I am getting unexpected error while trying to create post in Dynamics CRM. Below is the code:
Entity objEntity = new Entity("post");
objEntity["regardingobjectid"] = IncidentID;
objEntity["text"] = URLs;
objEntity["source"] = new OptionSetValue(2);
objEntity["type"] = new OptionSetValue(4);
Guid newPostID = lOrgService.Create(objEntity);
Please suggest what could be the problem.
It could be a multitude of things, which is hard to pinpoint based on the small amount of code you have submitted, but my best guess is that IncidentID is a GUID, where regardingobjectid should be an EntityReference.
Try replacing:
objEntity["regardingobjectid"] = IncidentID;
with
objEntity["regardingobjectid"] = new EntityReference("incident", IncidentID);

Null pointer exception on recognizer.allocate

I have a doubt in sphinx4-5 prealpha release. I'm not able to use class Recognizer, earlier in sphinx4 we were able to use like this: Recognizer recognizer = new Recognizer();
recognizer.allocate();
But the same piece of code in sphinx4-5 prealpha gives me nullPointerException at recognizer.allocate();
Code Snippet:
`Configuration cn = new Configuration();
cn.setAcousticModelPath(Acoustic_Model);
cn.setDictionaryPath(Dictionary_Path);
cn.setLanguageModelPath(LANGUAGE_MODEL);
Recognizer recognizer = new Recognizer();
recognizer.allocate();`
StackTrace: Exception in thread "main" java.lang.NullPointerException at edu.cmu.sphinx.recognizer.Recognizer.allocate(Recognizer.java:164) at edu.cmu.sphinx.demo.dialog.SampleSphinx.main(SampleSphinx.java:26) Exception is at recognizer.allocate
In sphinx4 we use to allocate resource from configuration like this:
Configuration configuration = new Configuration(); Recognizer recognizer = new Recognizer(); recognizer = (Recognizer) configuration.lookup();
but now as we know we use api in sphinx4-5 prealpha and we dont have lookup() in Configuration class. So how we will load JSGFGrammar and Recognizer in sphinx4-5 pre alpha. Hope I'm clear with my doubts please help in this #nikolay Thank You in advance.

How does one delete a solution using the CRM SDK?

Apologies if this is blindingly obvious, but I can't find info on how to do a deletion of a solution from an organisation via the SDK.
I've already done imports sucessfully, using an ImportSolutionRequest object, but can't find the equivalent thing for deleting solutions.
MS has a guide up on MSDN here
From that link
using (_serviceProxy = ServerConnection.GetOrganizationProxy(serverConfig))
{
// This statement is required to enable early-bound type support.
_serviceProxy.EnableProxyTypes();
// Delete a solution
QueryExpression queryImportedSolution = new QueryExpression
{
EntityName = Solution.EntityLogicalName,
ColumnSet = new ColumnSet(new string[] { "solutionid", "friendlyname" }),
Criteria = new FilterExpression()
};
queryImportedSolution.Criteria.AddCondition("uniquename", ConditionOperator.Equal, ImportedSolutionName);
Solution ImportedSolution = (Solution)_serviceProxy.RetrieveMultiple(queryImportedSolution).Entities[0];
_serviceProxy.Delete(Solution.EntityLogicalName, (Guid)ImportedSolution.SolutionId);
}

I dont have overload for EF savechanges, and no acceptallchanges available

I am very confused, i am trying in vain to queue up multiple inserts i have thousands of adds to do so i only want to really do the database once.
I am using .net 4 and entity framework 4 and also added reference to system.data.objects
but i still have no overload available for SaveChanges
here is my code:
using (TransactionScope scope = new TransactionScope())
{
using (myDbContext context = new myDbContext)
{
foreach (var p in model)
{
var tempProduct = new Products();
// set a loopable list of available products
IEnumerable<MerchantProductFeedMerchantProd> prod = p.prod;
foreach (var i in prod)
{
var prodText = i.text.FirstOrDefault();
var prodUri = i.uri.FirstOrDefault();
var prodPrice = i.price.FirstOrDefault();
FillTempProduct(feedId, i, tempProduct, supplierId, feedInfo, prodPrice, prodText,
prodUri);
context.Products.Add(tempProduct);
context.SaveChanges(false); // no overload
}
scope.Complete();
context.AcceptAllChanges(); //acceptallchanges not referenced ??
}
}
this is really battering my head now, so any help would be much appreciated.
thanks
Because you are using DbContext API and these methods are from ObjectContext API. DbContext API is simplified = it is only for simple requirements. If you have more complex requirements you must use ObjectContext API by converting your DbContext to ObjectContext instance:
var objectContext = ((IObjectContextAdapter)myDbContext).ObjectContext;

Resources