Get copy of Jena OntModel - jena

To get the Protege-OWL model as a Jena OntModel we use getOntModel(). How can we do the inverse action which copies the Jena OntModel to Protege-OWL model ?

Related

How can i add more than on paralel corpus or monolingual model into my custom model ? - Multiple inheritance

When I create a new model, how can I add more than one MonolingualCorpus or Parallel Corpus in Java because the method only accepts one InputStream for each model.
TranslationModel modelFirst = new CreateModelOptions.Builder()
.baseModelId("en-fr")
.name(p.getName())
.forcedGlossary(new FileInputStream(new File("forced1")))
.parallelCorpus(new FileInputStream(new File("paralel1")))
.monolingualCorpus(new FileInputStream(new File("mono1")))
.build();
Because otherwise, I don't understand the utility to create each time a new model if when I want to make a translation, I need to specify the ID of my custom model.
If I create a model with a forcedGlossary and a ParallelCorpus, the function returns me a new Model ID, for example, 12345.
After that, I want to add one ParallelCorpus and one Monolingual Model to this same model (ModelFirst). So I need to recreate a new model...
TranslationModel modelSecond = new CreateModelOptions.Builder()
.baseModelId(12345)
.name(p.getName())
.parallelCorpus(new FileInputStream(new File("paralel2")))
.monolingualCorpus(new FileInputStream(new File("mono2.txt")))
.build();
Now id of ModelSecond = 4567.
If I translate with the ModelFirst(12345), will Watson use the model from the ModelFirst AND from the ModelSecond or ONLY from the ModelFirst ??
If I translate with ModelSecond, Will it inherit my ModelFirst and basic model?
Can a model have multiple inheritance ?
You can create a model with only 1 Monolingual Corpus. If you need to add more than one I would suggest you combine the models into one.
Custom models can only be created out of base models. There is no such thing as an inheritance for custom models.

UI5 Can we create json model using just the entity type metadata from a service model

I want to create a model and set it as one of the global model in oninit method of component. I have a sap gateway odata service with just an entity type and do NOT have corresponding entityset.
My ui5 project has manifest.json with default model and component.js Is it possible to to create a model using just the metadata.
When you initialize the model, all you need is the metadata for initializing the SAPUI5 OData model. As long as the metadata is syntactically valid it should not be a problem. The EntitySets are only required when you assign an aggregation to a control using this model.
Update:
Its possible to get the details of the metadata from the model & create a new JSON model with it.
var oModel = new sap.ui.model.odata.ODataModel("http://services.odata.org/V2/OData/OData.svc");
var metaModel = oModel.getMetaModel();
var oEntitySet = metaModel.getODataEntitySet("Products"); //For getting properties of an Entity Set
//For Entity, you may have to provide the service namespace along, in this case ODataDemo
var oEntity = metaModel.getODataEntityType("ODataDemo.Product");
The oEntity object will look something like this
With this you can create a new JSON model as
var oODataJSONModel = new sap.ui.model.json.JSONModel({"Selection" : oEntity.property });
Here is a working example

poco class custom name

Is there a way to a coded class called "Pessoa" decorate some atttribute to be referenced with a conceptual class named as "Person" that is in a conceptual model ? I'm mean:
[Table("Person")] // or something like that
public class Pessoa
I tried
[EdmEntityTypeAttribute(Name = "Person")]
but no success....
Here is MS answer:
Currently, Entity Framework doesn't
support custom mapping between Object
and Conceptual types (names should
match). However, we will be
considering this feature for future
releases.
Thanks,
Kavitha Jonnakuti
Entity Framework test team

NHibernate: How do I XmlSerialize an ISet<T>?

Given:
I'm trying to create a REST API using ASP.NET MVC.
I'm using NHibernate in my data access layer.
Problem:
I'm can't XmlSerialize ISet properties.
I get errors like the following:
Cannot serialize member
[namespace].[entity].[property] of
type
Iesi.Collections.Generic.ISet`1[[namespace].[entity],
[assembly], Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null]]
because it is an interface.
I'll freely admit: I'm very new to NHibernate.
So I don't know what my options are.
I believe that I need to use a set as opposed to a bag because my collections contain unique items.
When I converted the ISet properties to HashedTable properties (i.e. a concrete class), I got errors like the following:
You must implement a default accessor
on
Iesi.Collections.Generic.HashedSet`1[[namespace].[entity],
[assembly],
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]] because it
inherits from ICollection.
My questions:
What should I do to remedy this situation?
Should I implement default accessors in all of my entity classes?
If so, is there a recommended pattern for doing so?
As a sidenote, I tried Googling for help.
- I don't think this is a new problem.
NHibernate serialization has been treated a lot on stackoverflow. See:
C# Castle ActiveRecord: How to elegantly (XML) serialize ActiveRecord objects?
How do I serialize all properties of an NHibernate-mapped object?
NHibernate and WCF Serialization(Unidirectional)
JSON.NET and nHibernate Lazy Loading of Collections
Which .NET JSON serializers can deal with NHibernate proxy objects?
DTOs vs Serializing Persisted Entities
Returning NHibernate mapping classes from WCF services
Bottom line: use DTOs.
Try using the DataContractSerializer instead. It's more restrictive, but will serialize more.
Dan Rigsby explains the difference between XMLSerializer and DataContractSerializer
Here's an example from one of my posts on stackoverflow:
public XDocument GetProductXML(Product product)
{
var serializer = new DataContractSerializer(typeof(Product));
var document = new XDocument();
using (var writer = document.CreateWriter())
{
serializer.WriteObject(writer, product);
writer.Close();
}
return document;
}
You can never XML Serialize an interface - only a concrete class that implements the interface.
1) Load the Dozer bean mapper from mapping file
DozerBeanMapper dtoMapper = new DozerBeanMapper(Arrays.asList(new String[]{dozerMappingfile}));
2) Covert each object to a normal object removing persistentbag related details
List<MyEjb> lstProfilehib = //hibernate loaded objects
List<MyEjb> lstProfile = new ArrayList<MyEjb>();
for(MyEjb sp: lstProfilehib){
lstProfile.add( dtoMapper.map(sp, MyEjb.class));
}

asp.net mvc: how to create custom binding for models when using LINQ to Entities

I've got a number of tables in my db that share common cols: modified by, modified date, etc. Not every table has these cols. We're using LINQ to Enties to generate the
I'd like to create a custom binder class that can handle the automatic binding of these fields. Is there a way to do this without having a custom binding class for each entity class?
Here's the code I have:
In global.asax.cs, Application_Start():
ModelBinders.Binders.Add(typeof(Foo),new FooBinder());
Then in FooBinder.cs:
public override Object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var obj = (Foo)base.BindModel(controllerContext, bindingContext);
var user = controllerContext.HttpContext.User.Identity;
obj.modified_by = user.Name;
obj.modified_date = DateTime.Now;
return obj;
}
Is there a way to generalize this so it can handle multiple types?
We do this in the repository, not in the binder. We have an interface with the common fields (Modified on). We implement the interface in partial classes which we codegen for our entities using a T4 template.
You can use reflection to set fields by name, so that you can do foreach over property names. This is not a big deal since model binder uses reflection itself to get to the properties, anyway. Then you can just register binder for each of the "common" types - which is also OK to do using reflection, for example by checking that entity has all fields required present - so it works even if you add new such entities.
Just have your binder call default one and then update the fields.

Resources