locked
Has anybody created an Entity Framework Model Extension for Zentity that is Ontology specific RRS feed

  • Question

  • I intend to use Zentity to store Ontology information.  "Ontology" is a loaded word, so I'll explain a bit further: Think: Multiple Taxonomies where each Taxonomy is a different type of relationship.  A single word or phrase (derived from Zentity.Core.Resource) would need to participate in multiple Taxonomies.  E.g. "Shrimp" has a relationship "Synonym" to "Paneus", "Shrimp" has a relationship "is a more specific type of" to "Crustacean", "Grand Isle" has a relationship "Is a habitat for" to "Shrimp".

     

    I am still very early in the process, but conceptually the Zentity Framework/ Data Model should be capable of this.  I just need to craft the Entity Framework Model correctly and import it using the powershell scripts........ or am I way off base?

    Has anybody gone down this road and could you share your experiences?

     

    TIA.


    Devhead
    Wednesday, February 1, 2012 10:00 PM

All replies

  • That is a great application of Zentity. Great thought!!

    A lot depends upon planning but yes Zentity Framework is very suitable for this application. The base thought I got while reading your post is

    word  ---> relationships (synonym, antonym, example, discription, translatedtospanish etc) ---> other word.

    Careful planning for Data Model and RDF files are required. You may also use other services into your app

    1) translation services from bing/goole.
    2) dictionary services of MS Office.
    3) Ontology services provided by other research or scientific organization. for example http://ucsdbiolit.codeplex.com/.

    Let me know if you find my reply helpful or of any further query.

    • Proposed as answer by Kalnemi Thursday, February 2, 2012 9:51 AM
    Thursday, February 2, 2012 9:51 AM
  • Hi Gump, I'm also in the process of learning how to use Zentity to store ontologies, but I've gotten as far as importing the US Presidents Sample right now. It's a steep learning curve, I can tell you that, but I'll blog about/document my experience and post the links here as I go along!

    Tuesday, February 21, 2012 9:24 PM
  • Hi Wizman,

    That would be great.  I've gotten as far as creating a custom data model "Zentity.Extensions.Ontology".  The model still needs some tweaking, but I have the basics working.  I can add Ontological "entities" (words) using the OOB Zentity editors and create various types of relationships among them, then visualize/PowerPivot them.  It's pretty cool.  Here is the basic custom model that I am using:  Executing this console app creates the model and updates the database, then I have to copy the created Zentity.Extensions.dll library to the various /bin folders in the zentity app and then.. run the Powershell script to update the Client Model.

    Details on how to update the client model with the PowerShell script:  http://social.microsoft.com/Forums/en-US/zentity/thread/b9749d71-a47a-4349-a63c-881649166c50

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.Serialization;
    using System.Data.Entity;
    using Zentity.Core;
    using System.IO;
    
    
    namespace CustomDataModelModule1
    {
        class Program
        {
            const string extensionsNameSpace = "Zentity.Extensions.Ontology";
            const string extensionAssemblyName = "Zentity.Extensions.Ontology";
    
            const string connectionStringFormat = @"provider=System.Data.SqlClient;
                    metadata=res://Zentity.Core; provider connection string='Data Source=.;
                    Initial Catalog=Zentity;Integrated Security=True;MultipleActiveResultSets=True'";
    
            static void Main(string[] args)
            {
                using (ZentityContext context = new ZentityContext(connectionStringFormat))
                {
                    ResourceType resourceTypeResource = context.DataModel.Modules["Zentity.Core"].ResourceTypes["Resource"];
    
                    // Create Data Model module.
                    DataModelModule module = new DataModelModule { NameSpace = extensionsNameSpace };
                    context.DataModel.Modules.Add(module);
    
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Create OntologicalEntity resource type.
                    ResourceType resourceTypeOntologicalEntity = new ResourceType
                    {
                        Name = "OntologicalEntity",
                        BaseType = resourceTypeResource,
                        Description = "Ontological Entity",
                        Uri = "SomeURITest"
                    };
    
                    // Add Self NavigationProperties
                    //NavigationProperty navIsAMoreSpecificFormOf = new NavigationProperty { Name = "IsAMoreSpecificFormOf" };
                    //resourceTypeOntologicalEntity.NavigationProperties.Add(navIsAMoreSpecificFormOf);
                    //NavigationProperty navIsAMoreGenericFormOf = new NavigationProperty { Name = "IsAMoreGenericFormOf" };
                    //resourceTypeOntologicalEntity.NavigationProperties.Add(navIsAMoreGenericFormOf);
                    //Association associationSpecificGeneric = new Association
                    //{
                    //    Name = "SpecificToGeneric",
                    //    SubjectNavigationProperty = navIsAMoreSpecificFormOf,
                    //    ObjectNavigationProperty = navIsAMoreGenericFormOf,
                    //    SubjectMultiplicity = AssociationEndMultiplicity.Many,
                    //    ObjectMultiplicity = AssociationEndMultiplicity.Many
                    //};
    
    
                    NavigationProperty navSynonyms = new NavigationProperty { Name = "Synonyms" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navSynonyms);
                    NavigationProperty navIsSynonymFor = new NavigationProperty { Name = "IsSynonymFor" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navIsSynonymFor);
                    Association associationSynonymous = new Association
                    {
                        Name = "Synonymous",
                        SubjectNavigationProperty = navSynonyms,
                        ObjectNavigationProperty = navIsSynonymFor,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
                    NavigationProperty navSubClass = new NavigationProperty { Name = "IsASubClassOf" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navSubClass);
                    NavigationProperty navSuperClass = new NavigationProperty { Name = "IsASuperClassOf" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navSuperClass);
                    Association associationSubClass = new Association
                    {
                        Name = "Taxonomy",
                        SubjectNavigationProperty = navSuperClass,
                        ObjectNavigationProperty = navSubClass,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
                    NavigationProperty navComprisedOf = new NavigationProperty { Name = "IsComprisedOf" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navComprisedOf);
                    NavigationProperty navIsMemberOf = new NavigationProperty { Name = "IsAMemberof" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navIsMemberOf);
                    Association associationGrouping = new Association
                    {
                        Name = "Grouping",
                        SubjectNavigationProperty = navComprisedOf,
                        ObjectNavigationProperty = navIsMemberOf,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
                    NavigationProperty navAbbreviation = new NavigationProperty { Name = "IsAbbreviationFor" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navAbbreviation);
                    NavigationProperty navUnabbreviated = new NavigationProperty { Name = "UnAbbreviatedForm" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navUnabbreviated);
                    Association associtationAbbreviation = new Association
                    {
                        Name = "Abbreviation",
                        SubjectNavigationProperty = navAbbreviation,
                        ObjectNavigationProperty = navUnabbreviated,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
                    NavigationProperty navMeasuredBy = new NavigationProperty { Name = "IsMeasuredIn" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navMeasuredBy);
                    NavigationProperty navCanMeasure = new NavigationProperty { Name = "IsMeasureOf" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navCanMeasure);
                    Association associtationUnits = new Association
                    {
                        Name = "Measure",
                        SubjectNavigationProperty = navMeasuredBy,
                        ObjectNavigationProperty = navCanMeasure,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
                    NavigationProperty navOwnerOf = new NavigationProperty { Name = "OwnerOf" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navOwnerOf);
                    NavigationProperty navIsOwnedBy = new NavigationProperty { Name = "IsOwnedBy" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navIsOwnedBy);
                    Association associtationOwner = new Association
                    {
                        Name = "Ownership",
                        SubjectNavigationProperty = navOwnerOf,
                        ObjectNavigationProperty = navIsOwnedBy,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
                    NavigationProperty navCollectorOf = new NavigationProperty { Name = "CollectorOf" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navCollectorOf);
                    NavigationProperty navIsCollectedBy = new NavigationProperty { Name = "IsCollectedBy" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navIsCollectedBy);
                    Association associtationCollection = new Association
                    {
                        Name = "Collection",
                        SubjectNavigationProperty = navCollectorOf,
                        ObjectNavigationProperty = navIsCollectedBy,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
                    NavigationProperty navProducerOf = new NavigationProperty { Name = "ProducerOf" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navProducerOf);
                    NavigationProperty navIsProducedBy = new NavigationProperty { Name = "IsProducedBy" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navIsProducedBy);
                    Association associtationProduction = new Association
                    {
                        Name = "Production",
                        SubjectNavigationProperty = navProducerOf,
                        ObjectNavigationProperty = navIsProducedBy,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
                    NavigationProperty navInhabitants = new NavigationProperty { Name = "Inhabitants" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navInhabitants);
                    NavigationProperty navInhabits = new NavigationProperty { Name = "Inhabits" };
                    resourceTypeOntologicalEntity.NavigationProperties.Add(navInhabits);
                    Association associtationHabitats = new Association
                    {
                        Name = "Habitats",
                        SubjectNavigationProperty = navInhabitants,
                        ObjectNavigationProperty = navInhabits,
                        SubjectMultiplicity = AssociationEndMultiplicity.Many,
                        ObjectMultiplicity = AssociationEndMultiplicity.Many
                    };
    
    
                    ////Add other NavigationProperties
                    //NavigationProperty navSMEs = new NavigationProperty { Name = "SubjectMatterExperts" };
                    //resourceTypeOntologicalEntity.NavigationProperties.Add(navSMEs);
                    // Add Scalar Properties
    
                    // For now, the "Title" in the base "Resource" will hold the "Value" (word or phrase)
                    // Neighborhood might need to be a first-class entity in the model with a NavigationProperty for OntologicalEntity.
                    ScalarProperty Neighborhood = new ScalarProperty { Name = "Neighborhood", DataType = DataTypes.String, MaxLength = 100 };
                    resourceTypeOntologicalEntity.ScalarProperties.Add(Neighborhood);
    
                    ScalarProperty Level = new ScalarProperty { Name = "Level", DataType = DataTypes.Int16 };
                    resourceTypeOntologicalEntity.ScalarProperties.Add(Level);
    
                    ScalarProperty Source = new ScalarProperty { Name = "Source", DataType = DataTypes.String, MaxLength = 400 };
                    resourceTypeOntologicalEntity.ScalarProperties.Add(Source);
    
                    ScalarProperty ApprovalStatus = new ScalarProperty { Name = "ApprovalStatus", DataType = DataTypes.String, MaxLength = 400 };
                    resourceTypeOntologicalEntity.ScalarProperties.Add(ApprovalStatus);
    
                    ScalarProperty Version = new ScalarProperty { Name = "Version", DataType = DataTypes.String, MaxLength = 50 };
                    resourceTypeOntologicalEntity.ScalarProperties.Add(Version);
    
    
                    //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    
                    //// Create Person resource type.
                    //ResourceType resourceTypePerson = new ResourceType { Name = "Person", BaseType = resourceTypeResource };
                    //module.ResourceTypes.Add(resourceTypePerson);
                    //NavigationProperty navExpertInSubjects = new NavigationProperty { Name = "ExpertInSubjects" };
                    //resourceTypePerson.NavigationProperties.Add(navExpertInSubjects);
    
                    //// Create associationSMEs.
                    //Association associationSMEs = new Association
                    //{
                    //    Name = "OntologicalEntityHasSMEs",
                    //    SubjectNavigationProperty = navSMEs,
                    //    ObjectNavigationProperty = navExpertInSubjects,
                    //    SubjectMultiplicity = AssociationEndMultiplicity.Many,
                    //    ObjectMultiplicity = AssociationEndMultiplicity.Many
                    //};
                    module.ResourceTypes.Add(resourceTypeOntologicalEntity);
    
                    // Synchronize the in-memory models with the backend.
                    context.DataModel.Synchronize();
    
                    // Generate Extensions Assembly.
                    //using (FileStream fout = new FileStream(@"D:\Zentity\Zentity.Extensions.Ontology.dll", FileMode.Create, FileAccess.Write))
                    //{
                    //    byte[] rawAssembly = context.DataModel.GenerateExtensionsAssembly(
                    //        extensionAssemblyName, true, null, new string[] { extensionsNameSpace }, null);
                    //    fout.Write(rawAssembly, 0, rawAssembly.Length);
                    //}
                    using (FileStream fout = new FileStream(@"D:\Zentity\Zentity.Extensions.Ontology.dll", FileMode.Create, FileAccess.Write))
                    {
                        byte[] rawAssembly = context.DataModel.GenerateExtensionsAssembly(
                            extensionAssemblyName, true, null, null, null);
                        fout.Write(rawAssembly, 0, rawAssembly.Length);
                    }
    
                    // Generate Entity Framework artifacts.
                    EFArtifactGenerationResults results = context.DataModel.GenerateEFArtifacts(extensionsNameSpace);
                    results.Csdls.Where(tuple => tuple.Key == "Zentity.Core").First().Value.Save(@"D:\Zentity\ExtendedCore.csdl");
                    results.Csdls.Where(tuple => tuple.Key == extensionsNameSpace).First().Value.Save(@"D:\Zentity\Zentity.Extensions.Ontology.csdl");
                    results.Msl.Save(@"D:\Zentity\Consolidated.msl");
                    results.Ssdl.Save(@"D:\Zentity\Consolidated.ssdl");
                }
            }
        }
    
    }
    


    Devhead

    Friday, February 24, 2012 3:23 PM
  • Wow, thanks for the code! It's certainly useful for learning about the model. Right now I've been able to generate a model from RDF (this is the usecase for me) and I've managed to load data into the model and get it displayed in Visual Explorer and Pivot viewer. 

    One thing I've not been able to find out is: After initially importing the data model via PowerShell, is there any way to change the model definition? The documentation seems to suggest it is possible, but someone who has worked a lot with Zentity said that would not be possible. I'm kind of trying to work that out now

    Quoting from the Zentity.Core.ResourceType entry:

    "Example below shows how to introduce and remove resource types from the data model."


    Saturday, February 25, 2012 9:30 PM
  • Hi WizMan,

    Zentity client applications (WebUI and Zentity Resource Manager) provides convenient way to change the model definations. You cannot change namespaces name and uris but rest you can update using the above applications.

    If you have stuck on some point in your task please let us know with details. We will work out to find a solution.

    -Regards

    • Proposed as answer by WizMan Tuesday, February 28, 2012 7:49 PM
    Monday, February 27, 2012 7:40 AM