Package edu.isi.karma.modeling.ontology

Examples of edu.isi.karma.modeling.ontology.OntologyManager


    //    if (true)
    //      return;

    List<SemanticModel> trainingData = new ArrayList<SemanticModel>();

    OntologyManager ontologyManager = new OntologyManager();
    File ff = new File(Params.ONTOLOGY_DIR);
    File[] files = ff.listFiles();
    for (File f : files) {
      ontologyManager.doImport(f, "UTF-8");
    }
    ontologyManager.updateCache()

//    getStatistics1(semanticModels);
//
//    if (true)
//      return;
View Full Code Here


        path, sel);
    if (trainingExamples.size() == 0)
      return null;

    ISemanticTypeModelHandler modelHandler = workspace.getSemanticTypeModelHandler();
    OntologyManager ontologyManager = workspace.getOntologyManager();
   
    List<SemanticTypeLabel> result = modelHandler.predictType(trainingExamples, numSuggestions);
    if (result == null) {
      logger.debug("Error occured while predicting semantic type.");
      return null;
    }
    if (result.size() == 0) {
      return null;
    }

    /** Remove the labels that are not in the ontology or are already used as the semantic type **/
    List<SemanticTypeLabel> removeLabels = new ArrayList<SemanticTypeLabel>();
    String domainUri, typeUri;
    Label domain, type;
    for (int i=0; i<result.size(); i++) {
      SemanticTypeLabel semLabel = result.get(i);
      String label = semLabel.getLabel();
      /** Check if not in ontology **/
      if (label.contains("|")) {
       
        domainUri = label.split("\\|")[0].trim();
        typeUri = label.split("\\|")[1].trim();
       
        domain = ontologyManager.getUriLabel(domainUri);
        type = ontologyManager.getUriLabel(typeUri);
       
        // Remove from the list if URI not present in the model
        if (domain == null || type == null) {
          removeLabels.add(semLabel);
          continue;
        }
               
      } else {
        domain = ontologyManager.getUriLabel(label);
        // Remove from the list if URI not present in the model
        if (domain == null) {
          removeLabels.add(semLabel);
          continue;
        }
View Full Code Here

  public ArrayList<SemanticType> getColumnSemanticSuggestions(Workspace workspace, Worksheet worksheet, ColumnNode cn, int numSuggestions, SuperSelection sel) {
    ArrayList<SemanticType> suggestedSemanticTypes = new ArrayList<SemanticType>();
    logger.info("Column Semantic Suggestions for:" + cn.getColumnName());
    if(workspace != null && worksheet != null) {
      OntologyManager ontologyManager = workspace.getOntologyManager();
      String hNodeId = cn.getHNodeId();
      SemanticTypeColumnModel columnModel = predictColumnSemanticType(workspace, worksheet, hNodeId, numSuggestions, sel);
     
      if (columnModel != null) {
        for (Entry<String, Double> entry : columnModel.getScoreMap().entrySet()) {
 
          String key = entry.getKey();
          Double confidence = entry.getValue();
          if (key == null || key.isEmpty()) continue;
 
          String[] parts = key.split("\\|");
          if (parts == null || parts.length != 2) continue;
 
          String domainUri = parts[0].trim();
          String propertyUri = parts[1].trim();
 
          Label domainLabel = ontologyManager.getUriLabel(domainUri);
          if (domainLabel == null) continue;
 
          Label propertyLabel = ontologyManager.getUriLabel(propertyUri);
          if (propertyLabel == null) continue;
 
          SemanticType semanticType = new SemanticType(hNodeId, propertyLabel, domainLabel, Origin.CRFModel, confidence);
          logger.info("\t" + propertyUri + " of " + domainUri + ": " + confidence);
          suggestedSemanticTypes.add(semanticType);
View Full Code Here

     
    }
    /*** Get the Alignment for this worksheet ***/
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    OntologyManager ontMgr = workspace.getOntologyManager();
    String alignmentId = AlignmentManager.Instance().constructAlignmentId(
        workspace.getId(), worksheetId);
    Alignment alignment = AlignmentManager.Instance().getAlignment(
        alignmentId);
    if (alignment == null) {
      alignment = new Alignment(ontMgr);
      AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
    }

    // Save the original alignment for undo
    oldAlignment = alignment.getAlignmentClone();
    oldGraph = (DirectedWeightedMultigraph<Node, DefaultLink>) alignment
        .getGraph().clone();

    /*** Add the appropriate nodes and links in alignment graph ***/
    newType = null;

    /** Check if a semantic type already exists for the column **/
    ColumnNode columnNode = alignment.getColumnNodeByHNodeId(hNodeId);
    columnNode.setRdfLiteralType(rdfLiteralType);
    boolean semanticTypeAlreadyExists = false;
    LabeledLink oldIncomingLinkToColumnNode = null;
    Node oldDomainNode = null;
    List<LabeledLink> columnNodeIncomingLinks = alignment
        .getIncomingLinks(columnNode.getId());
    if (columnNodeIncomingLinks != null
        && !columnNodeIncomingLinks.isEmpty()) { // SemanticType already
                              // assigned
      semanticTypeAlreadyExists = true;
      oldIncomingLinkToColumnNode = columnNodeIncomingLinks.get(0);
      oldDomainNode = oldIncomingLinkToColumnNode.getSource();
    }

    if(metaPropertyId.endsWith(" (add)"))
      metaPropertyId = metaPropertyId.substring(0, metaPropertyId.length()-5).trim();
   
  if (metaPropertyName.equals(METAPROPERTY_NAME.isUriOfClass)) {
      Node classNode = alignment.getNodeById(metaPropertyId);
      if (semanticTypeAlreadyExists) {
        clearOldSemanticTypeLink(oldIncomingLinkToColumnNode,
            oldDomainNode, alignment, classNode);
      }

      if (classNode == null) {
        Label classNodeLabel = ontMgr.getUriLabel(metaPropertyUri);
        if (classNodeLabel == null) {
          String errorMessage = "Error while setting a classLink. MetaPropertyUri '"
              + metaPropertyUri
              + "' should be in the Ontology Manager, but it is not.";
          logger.error(errorMessage);
          return new UpdateContainer(new ErrorUpdate(errorMessage));
        }
        classNode = alignment.addInternalNode(classNodeLabel);
      }

      LabeledLink newLink = alignment.addClassInstanceLink(classNode, columnNode,
          LinkKeyInfo.UriOfInstance);
      alignment.changeLinkStatus(newLink.getId(),
          LinkStatus.ForcedByUser);
     
      // Create the semantic type object
      newType = new SemanticType(hNodeId,
          ClassInstanceLink.getFixedLabel(), classNode.getLabel(),
          SemanticType.Origin.User, 1.0);
    } else if (metaPropertyName
        .equals(METAPROPERTY_NAME.isSpecializationForEdge)) {
      LabeledLink propertyLink = alignment.getLinkById(metaPropertyId);
      if (propertyLink == null) {
        String errorMessage = "Error while specializing a link. The DefaultLink '"
            + metaPropertyId
            + "' should already be in the alignment, but it is not.";
        logger.error(errorMessage);
        return new UpdateContainer(new ErrorUpdate(errorMessage));
      }

      Node classInstanceNode = alignment.getNodeById(LinkIdFactory
          .getLinkSourceId(metaPropertyId));
      if (semanticTypeAlreadyExists) {
        clearOldSemanticTypeLink(oldIncomingLinkToColumnNode,
            oldDomainNode, alignment, classInstanceNode);
      }

      if (propertyLink instanceof DataPropertyLink) {
        String targetHNodeId = ((ColumnNode) propertyLink.getTarget())
            .getHNodeId();
        LabeledLink newLink = alignment.addDataPropertyOfColumnLink(classInstanceNode,
            columnNode, targetHNodeId, propertyLink.getId());
        alignment.changeLinkStatus(newLink.getId(),
            LinkStatus.ForcedByUser);
       
        // Create the semantic type object
        newType = new SemanticType(hNodeId,
            DataPropertyOfColumnLink.getFixedLabel(),
            classInstanceNode.getLabel(), SemanticType.Origin.User,
            1.0);
      } else if (propertyLink instanceof ObjectPropertyLink) {
        LabeledLink newLink = alignment.addObjectPropertySpecializationLink(
            classInstanceNode, columnNode, propertyLink.getId());
        alignment.changeLinkStatus(newLink.getId(),
            LinkStatus.ForcedByUser);

        // Create the semantic type object
        newType = new SemanticType(hNodeId,
            ObjectPropertySpecializationLink.getFixedLabel(),
            classInstanceNode.getLabel(), SemanticType.Origin.User,
            1.0);
      }

    } else if (metaPropertyName.equals(METAPROPERTY_NAME.isSubclassOfClass)) {
      Node classNode = alignment.getNodeById(metaPropertyId);
      if (semanticTypeAlreadyExists) {
        clearOldSemanticTypeLink(oldIncomingLinkToColumnNode,
            oldDomainNode, alignment, classNode);
      }

      if (classNode == null) {
        Label classNodeLabel = ontMgr.getUriLabel(metaPropertyUri);
        if (classNodeLabel == null) {
          String errorMessage = "Error while setting an advances subclass. MetaPropertyValue '"
              + metaPropertyUri
              + "' should be in the Ontology Manager, but it is not.";
          logger.error(errorMessage);
View Full Code Here

    //    if (true)
    //      return;

    List<SemanticModel> trainingData = new ArrayList<SemanticModel>();

    OntologyManager ontologyManager = new OntologyManager();
    File ff = new File(Params.ONTOLOGY_DIR);
    File[] files = ff.listFiles();
    for (File f : files) {
      ontologyManager.doImport(f, "UTF-8");
    }
    ontologyManager.updateCache()

//    getStatistics1(semanticModels);

//    if (true)
//      return;
View Full Code Here

    SuperSelection selection = getSuperSelection(worksheet);
    RepFactory f = workspace.getFactory();
    Alignment alignment = AlignmentManager.Instance().getAlignment(
        AlignmentManager.Instance().constructAlignmentId(workspace.getId(),
            worksheetId));
    OntologyManager ontMgr = workspace.getOntologyManager();
    // Set the prefix and namespace to be used while generating RDF
    fetchRdfPrefixAndNamespaceFromPreferences(workspace);
   
    // Generate the KR2RML data structures for the RDF generation
    final ErrorReport errorReport = new ErrorReport();
View Full Code Here

    SuperSelection selection = getSuperSelection(worksheet);
    RepFactory f = workspace.getFactory();
    Alignment alignment = AlignmentManager.Instance().getAlignment(
        AlignmentManager.Instance().constructAlignmentId(workspace.getId(),
            worksheetId));
    OntologyManager ontMgr = workspace.getOntologyManager();
    // Set the prefix and namespace to be used while generating RDF
    fetchRdfPrefixAndNamespaceFromPreferences(workspace);

    // Generate the KR2RML data structures for the RDF generation
    final ErrorReport errorReport = new ErrorReport();
View Full Code Here

    super(workspace);
  }
 
  @Override
  public void setup(UpdateContainer uc) {
    OntologyManager ontologyManager = workspace.getOntologyManager();
    if (ModelingConfiguration.isLearnerEnabled())
      new ModelLearningGraphLoaderThread(ontologyManager).run();
  }
View Full Code Here

    Worksheet worksheet = workspace.getWorksheet(worksheetId);

    worksheetName = worksheet.getTitle();

    // Generate the semantic types for the worksheet
    OntologyManager ontMgr = workspace.getOntologyManager();
    if(ontMgr.isEmpty())
      return new UpdateContainer(new ErrorUpdate("No ontology loaded."));


    String alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
    Alignment alignment = AlignmentManager.Instance().getAlignment(alignmentId);
View Full Code Here

    return CommandType.notInHistory;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    final OntologyManager ontMgr = workspace.getOntologyManager();
    Set<LabeledLink> properties = new HashSet<>();
   
    logger.debug("GetPropertiesCommand:" + propertiesRange + ":" + classURI + "," + domainURI + ", " +  rangeURI);
   
    if (propertiesRange == INTERNAL_PROP_RANGE.allObjectProperties) {
      HashMap<String, Label> linkList = ontMgr.getObjectProperties();
      if(linkList != null) {
        for(Label label : linkList.values()) {
          properties.add(new ObjectPropertyLink(label.getUri(), label, ObjectPropertyType.None));
        }
      }
    } else if(propertiesRange == INTERNAL_PROP_RANGE.allDataProperties) {
      HashMap<String, Label> linkList = ontMgr.getDataProperties();
      for(Label label : linkList.values()) {
        properties.add(new DataPropertyLink(label.getUri(), label));
      }
    } else if(propertiesRange == INTERNAL_PROP_RANGE.allDataAndObjectProperties) {
      HashMap<String, Label> linkList = ontMgr.getDataProperties();
      for(Label label : linkList.values()) {
        properties.add(new DataPropertyLink(label.getUri(), label));
      }
      HashMap<String, Label> objectLinkList = ontMgr.getObjectProperties();
      for(Label label : objectLinkList.values()) {
        if(!linkList.containsValue(label))
          properties.add(new ObjectPropertyLink(label.getUri(), label, ObjectPropertyType.None));
      }
    } else if(propertiesRange == INTERNAL_PROP_RANGE.propertiesWithDomainRange) {
      Map<String, Label> linkList = ontMgr.getObjectPropertiesByDomainRange(domainURI, rangeURI, true);
      for(Label label : linkList.values()) {
        properties.add(new DataPropertyLink(label.getUri(), label));
      }
    } else if(propertiesRange == INTERNAL_PROP_RANGE.dataPropertiesForClass) {
      Map<String, Label> linkList = ontMgr.getDataPropertiesByDomain(classURI, true);
      for(Label label : linkList.values()) {
        properties.add(new DataPropertyLink(label.getUri(), label));
      }
    } else if(propertiesRange == INTERNAL_PROP_RANGE.existingProperties) {
      Alignment alignment = AlignmentManager.Instance().getAlignmentOrCreateIt(workspace.getId(), worksheetId, ontMgr);
View Full Code Here

TOP

Related Classes of edu.isi.karma.modeling.ontology.OntologyManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.