Package edu.isi.karma.modeling.ontology

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


      autoOntology.Build(path);
    } catch (IOException e) {
      logger.error("Error occured while creating auto model!", e);
    }

    OntologyManager ontMgr = workspace.getOntologyManager();
    File autoOtologyFile = new File(path);
    logger.info("Loading ontology: " + autoOtologyFile.getAbsolutePath());
    String encoding = EncodingDetector.detect(autoOtologyFile);
    try {
      ontMgr.doImportAndUpdateCache(autoOtologyFile, encoding);
      logger.info("Done loading ontology: "
          + autoOtologyFile.getAbsolutePath());
    } catch(Exception e) {
      logger.error("Error importing auto ontology file: " + autoOtologyFile.getAbsolutePath());
    }
   
    SuggestAutoModelCommand comm = new SuggestAutoModelCommand(
        getNewId(workspace), worksheet.getId());
    // Add the semantic types that have saved into the history
    for (int i = 2; i < inputJson.length(); i++) {
      JSONObject hnodeObj = (JSONObject) inputJson.get(i);
      String hNodeId = (String) hnodeObj.get(ClientJsonKeys.value
          .name());

      JSONObject typeObj = (JSONObject) inputJson.get(++i);
      JSONObject value = (JSONObject) typeObj
          .get(ClientJsonKeys.value.name());

      SemanticType type = null;
      String domain = (String) value
          .get(SemanticType.ClientJsonKeys.DomainUri.name());
      String fullType = (String) value
          .get(SemanticType.ClientJsonKeys.FullType.name());
     
      Label typeName = ontMgr.getUriLabel(fullType);
      Label domainName = null;
      if (domain != null && !domain.trim().equals(""))
        domainName = ontMgr.getUriLabel(domain);

      if (typeName != null) {
        type = new SemanticType(hNodeId, typeName, domainName,
            Origin.User, 1.00);
        worksheet.getSemanticTypes().addType(type);
View Full Code Here


    }catch(Exception e) {
     
    }
    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 ***/
    List<SemanticType> typesList = new ArrayList<SemanticType>();
    for (int i = 0; i < typesArr.length(); i++) {
      try {
        LabeledLink newLink = null;
        JSONObject type = typesArr.getJSONObject(i);
       
        String domainValue;
        // For property semantic types, domain uri goes to "domainValue" and link uri goes to "fullTypeValue".
        // For class semantic type, class uri goes "fullTypeValue" and "domainValue" is empty.
        if(type.has(ClientJsonKeys.DomainId.name()))
          domainValue = type.getString(ClientJsonKeys.DomainId.name());
        else
          domainValue = type.getString("Domain"); //For backward compatibility to older models
        String fullTypeValue = type.getString(ClientJsonKeys.FullType.name());
//        logger.trace("FULL TYPE:" + type.getString(ClientJsonKeys.FullType.name()));
//        logger.trace("Domain: " + type.getString(ClientJsonKeys.Domain.name()));
       
        // Look if the domain value exists. If it exists, then it is a domain of a data property. If not
        // then the value in FullType has the the value which indicates if a new class instance is needed
        // or an existing class instance should be used (this is the case when just the class is chosen as a sem type).
//        Label domainName = null;
       
        boolean isClassSemanticType = false;
        boolean semanticTypeAlreadyExists = false;
        Node domain = null;
        String domainUriOrId;
        Label linkLabel;
       
        // if domain value is empty, semantic type is a class semantic type
        if (domainValue.equals("")) {
          isClassSemanticType = true;
          domainUriOrId = fullTypeValue;
          linkLabel = ClassInstanceLink.getFixedLabel();
        } else {
          isClassSemanticType = false;
          domainUriOrId = domainValue;
          linkLabel = ontMgr.getUriLabel(fullTypeValue);
          if (linkLabel == null) {
            logger.error("URI/ID does not exist in the ontology or model: " + fullTypeValue);
            continue;
          }
        }
       
        if(domainUriOrId.endsWith(" (add)"))
          domainUriOrId = domainUriOrId.substring(0, domainUriOrId.length()-5).trim();
       
        domain = alignment.getNodeById(domainUriOrId);
        logger.info("Got domain for domainUriOrId:" + domainUriOrId + " ::" + domain);
        if (domain == null) {
          Label label = ontMgr.getUriLabel(domainUriOrId);
//          if (label == null) {
//            logger.error("URI/ID does not exist in the ontology or model: " + domainUriOrId);
//            continue;
//          }
          if (label == null) {
            if(type.has(ClientJsonKeys.DomainUri.name())) {
              label = new Label(type.getString(ClientJsonKeys.DomainUri.name()));
            } else {
              //This part of the code is for backward compatibility. Newer models should have domainUri
              int len = domainValue.length();
              if ((len > 1) && Character.isDigit(domainValue.charAt(len-1))) {
                String newDomainValue = domainValue.substring(0, len-1);
                label = ontMgr.getUriLabel(newDomainValue);
              }
              if (label == null) {
                logger.error("No graph node found for the node: " + domainValue);
                return new UpdateContainer(new ErrorUpdate("" +
                "Error occured while setting semantic type!"));
View Full Code Here

      nodeSet = getAllClasses(workspace);
    } else if(range == INTERNAL_NODES_RANGE.classesWithProperty) {
      nodeSet = getClassesWithProperty(workspace, propertyURI);
    }
    else if (range == INTERNAL_NODES_RANGE.allClassesRaw) {
      final OntologyManager ontMgr = workspace.getOntologyManager();
      final HashMap<String, Label> allClasses = ontMgr.getClasses();
      UpdateContainer upd = new UpdateContainer(new AbstractUpdate() {
        @Override
        public void generateJson(String prefix, PrintWriter pw,
            VWorkspace vWorkspace) {
          JSONArray nodesArray = new JSONArray();
View Full Code Here

    });
    return upd;
  }

  private Set<Node> getAllClasses(Workspace workspace) {
    final OntologyManager ontMgr = workspace.getOntologyManager();
    HashMap<String, Label> allClasses = ontMgr.getClasses();

    logger.info("Got " + allClasses.size() + " classes from OntologyManager");

    Set<Label> nodeLabels = new HashSet<>();
    nodeLabels.addAll(allClasses.values());
View Full Code Here

        workspace.getId(), worksheetId);
    return alignment.getSteinerTree().vertexSet();
  }

  private Set<Node> getClassesWithProperty(Workspace workspace, String propertyURI) {
    final OntologyManager ontMgr = workspace.getOntologyManager();
    final HashSet<String> domains = ontMgr.getDomainsOfProperty(
        propertyURI, true);
    if (domains == null || domains.size() == 0) {
      return null;
    }

    Set<Label> nodeLabels = new HashSet<>();
    for(String domain : domains) {
      Label domainURI = ontMgr.getUriLabel(domain);
      if(domainURI == null)
        continue;
      nodeLabels.add(domainURI);
    }
View Full Code Here

    return getNodesUsingAlignment(workspace, nodeLabels);
  }

  private Set<Node> getNodesUsingAlignment(Workspace workspace, Set<Label> nodeLabels) {
    Set<Node> nodeSet = new HashSet<>();
    final OntologyManager ontMgr = workspace.getOntologyManager();
    final Alignment alignment = AlignmentManager.Instance().getAlignmentOrCreateIt(
        workspace.getId(), worksheetId, ontMgr);

    final Set<String> steinerTreeNodeIds = new HashSet<String>();
View Full Code Here

    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    this.normalizeSelectionId(worksheetId, inputJson, workspace);
    String selectionName = CommandInputJSONUtil.getStringValue(Arguments.selectionName.name(), inputJson);
    SuggestModelCommand comm = new SuggestModelCommand(getNewId(workspace), worksheet.getId(), false,
        selectionName);
    OntologyManager ontMgr = workspace.getOntologyManager();
    // Add the semantic types that have saved into the history
    for (int i=2; i<inputJson.length(); i++) {
      JSONObject hnodeObj = (JSONObject) inputJson.get(i);
      String hNodeId = (String) hnodeObj.get(ClientJsonKeys.value.name());
     
      JSONObject typeObj = (JSONObject) inputJson.get(++i);
      JSONObject value = (JSONObject) typeObj.get(ClientJsonKeys.value.name());
     
      SemanticType type = null;
      String domain = (String) value.get(SemanticType.ClientJsonKeys.DomainUri.name());
      String fullType = (String) value.get(SemanticType.ClientJsonKeys.FullType.name());
     
      Label typeName = ontMgr.getUriLabel(fullType);
      Label domainName = null;
      if (domain != null && !domain.trim().equals(""))
        domainName = ontMgr.getUriLabel(domain);
     
      if(typeName != null) {
        type = new SemanticType(hNodeId, typeName, domainName, Origin.User, 1.00);
        worksheet.getSemanticTypes().addType(type);
      }
View Full Code Here

//      SemanticTypeUtil.populateSemanticTypesUsingCRF(worksheet, workspace
//          .getTagsContainer().getTag(TagName.Outlier), workspace
//          .getSemanticTypeModelHandler(), workspace.getOntologyManager());
//    }

    OntologyManager om= workspace.getOntologyManager();
    WorksheetToFeatureCollection geo = new WorksheetToFeatureCollection(worksheet, om, selection);//ying
    //WorksheetToFeatureCollections geo = new WorksheetToFeatureCollections(worksheet);
    // Send an error update if no geospatial data found!
    if (geo.hasNoGeospatialData()) {
      return new UpdateContainer(new ErrorUpdate(
View Full Code Here

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);

    OntologyManager om= workspace.getOntologyManager();
    WorksheetToFeatureCollection geo = new WorksheetToFeatureCollection(worksheet, om, selection);//ying
   
    // Send an error update if no geospatial data found!
    if (geo.hasNoGeospatialData()) {
      return new UpdateContainer(new ErrorUpdate(
View Full Code Here

 
  public static void main(String[] args) throws Exception {

    ServletContextParameterMap.setParameterValue(ContextParameter.USER_CONFIG_DIRECTORY, "/Users/mohsen/karma/config");

    OntologyManager ontologyManager = new OntologyManager();
    File ff = new File(Params.ONTOLOGY_DIR);
    File[] files = ff.listFiles();
    if (files == null) {
      logger.error("no ontology to import at " + ff.getAbsolutePath());
      return;
    }

    for (File f : files) {
      if (f.getName().endsWith(".owl") ||
          f.getName().endsWith(".rdf") ||
          f.getName().endsWith(".n3") ||
          f.getName().endsWith(".ttl") ||
          f.getName().endsWith(".xml")) {
        logger.info("Loading ontology file: " + f.getAbsolutePath());
        ontologyManager.doImport(f, "UTF-8");
      }
    }
    ontologyManager.updateCache();


    String outputPath = Params.OUTPUT_DIR;
    String graphPath = Params.GRAPHS_DIR;
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.