Package edu.isi.karma.rep

Examples of edu.isi.karma.rep.Worksheet


  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    RepFactory repFactory = workspace.getFactory();
    HTable ht = repFactory.getHTable(repFactory.getHNode(hNodeId).getHTableId());
    //remove the new column
    ht.removeHNode(newHNodeId, worksheet);
View Full Code Here


    return CommandType.notUndoable;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    RepFactory factory = workspace.getFactory();
    SuperSelection superSel = getSuperSelection(worksheet);
    HTable hTable = factory.getHTable(factory.getHNode(hNodeId).getHTableId());
    Selection currentSel = superSel.getSelection(hTable.getId());
    if (currentSel != null) {
View Full Code Here

    return CommandType.notInHistory;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
   
    // Check if the model name exists. If not set to a default one
    String graphLabel = worksheet.getMetadataContainer().getWorksheetProperties().
        getPropertyValue(Property.graphLabel);

    if (graphLabel == null || graphLabel.isEmpty()) {
        worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
            Property.graphLabel, worksheet.getTitle());
        graphLabel = worksheet.getTitle();
        worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
            Property.graphName, WorksheetProperties.createDefaultGraphName(graphLabel))
    }
   
    String baseURI = worksheet.getMetadataContainer().getWorksheetProperties().
        getPropertyValue(Property.baseURI);

    if (baseURI == null || baseURI.isEmpty()) {
        worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
            Property.baseURI, "http://localhost:8080/source/")
    }
   
    String prefix = worksheet.getMetadataContainer().getWorksheetProperties().
        getPropertyValue(Property.prefix);

    if (prefix == null || prefix.isEmpty()) {
        worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
            Property.prefix, "s")
    }
   
   
   
    WorksheetProperties props = worksheet.getMetadataContainer().getWorksheetProperties();
    try {
      final JSONObject propsJson = props.getJSONRepresentation();
      return new UpdateContainer(new AbstractUpdate() {
       
        @Override
View Full Code Here

      HNode hn = workspace.getFactory().getHNode(hNodeId);
      labelName = hn.getColumnName();
    }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!"));
              }
            }
          }
          domain = alignment.addInternalNode(label);
        }
         
        // Check if a semantic type already exists for the column
        ColumnNode columnNode = alignment.getColumnNodeByHNodeId(hNodeId);
        columnNode.setRdfLiteralType(rdfLiteralType);
        List<LabeledLink> columnNodeIncomingLinks = alignment.getIncomingLinks(columnNode.getId());
        LabeledLink oldIncomingLinkToColumnNode = null;
        Node oldDomainNode = null;
        if (columnNodeIncomingLinks != null && !columnNodeIncomingLinks.isEmpty()) { // SemanticType already assigned
          semanticTypeAlreadyExists = true;
          oldIncomingLinkToColumnNode = columnNodeIncomingLinks.get(0);
          oldDomainNode = oldIncomingLinkToColumnNode.getSource();
        }

        if (type.getBoolean(ClientJsonKeys.isPrimary.name())) {
         
          if (isClassSemanticType) {
            if (semanticTypeAlreadyExists && oldDomainNode == domain) {
              newLink = oldIncomingLinkToColumnNode;
              // do nothing;
            } else if (semanticTypeAlreadyExists) {
              alignment.removeLink(oldIncomingLinkToColumnNode.getId());
//              alignment.removeNode(oldDomainNode.getId());
              newLink = alignment.addClassInstanceLink(domain, columnNode, LinkKeyInfo.None);
            } else {
              newLink = alignment.addClassInstanceLink(domain, columnNode, LinkKeyInfo.None);
            }
          }
          // Property semantic type
          else {

            // When only the link changes between the class node and the internal node (domain)
            if (semanticTypeAlreadyExists && oldDomainNode == domain) {
              alignment.removeLink(oldIncomingLinkToColumnNode.getId());
              newLink = alignment.addDataPropertyLink(domain, columnNode, linkLabel);
            }
            // When there was an existing semantic type and the new domain is a new node in the graph and semantic type already existed
            else if (semanticTypeAlreadyExists) {
              alignment.removeLink(oldIncomingLinkToColumnNode.getId());
//              alignment.removeNode(oldDomainNode.getId());
              newLink = alignment.addDataPropertyLink(domain, columnNode, linkLabel);
            } else {
              newLink = alignment.addDataPropertyLink(domain, columnNode, linkLabel);
            }           
          }
        } else { // Synonym semantic type
          SemanticType synType = new SemanticType(hNodeId, linkLabel, domain.getLabel(), SemanticType.Origin.User, 1.0);
          typesList.add(synType);
        }
       
        // Create the semantic type object
        newType = new SemanticType(hNodeId, linkLabel, domain.getLabel(), SemanticType.Origin.User, 1.0);
//        newType = new SemanticType(hNodeId, classNode.getLabel(), null, SemanticType.Origin.User, 1.0,isPartOfKey);
        columnNode.setUserSelectedSemanticType(newType);
       
        if(newLink != null) {
          alignment.changeLinkStatus(newLink.getId(),
              LinkStatus.ForcedByUser);
        }
        // Update the alignment
        if(!this.isExecutedInBatch())
          alignment.align();

      } catch (JSONException e) {
        logger.error("JSON Exception occured", e);
      }
    }
   
    UpdateContainer c = new UpdateContainer();

    // Save the old SemanticType object and CRF Model for undo
    oldType = worksheet.getSemanticTypes().getSemanticTypeForHNodeId(hNodeId);
    oldSynonymTypes = worksheet.getSemanticTypes().getSynonymTypesForHNodeId(hNodeId);

    if (newType != null) {
      // Update the SemanticTypes data structure for the worksheet
      worksheet.getSemanticTypes().addType(newType);

      // Update the synonym semanticTypes
      newSynonymTypes = new SynonymSemanticTypes(typesList);
      worksheet.getSemanticTypes().addSynonymTypesForHNodeId(newType.getHNodeId(), newSynonymTypes);
    }

    // Identify the outliers if the semantic type exists in the crfmodel
//    List<String> existingLabels = new ArrayList<String>();
//    crfModelHandler.getLabels(existingLabels);
View Full Code Here

//  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    UpdateContainer c = new UpdateContainer();
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    if (oldType == null) {
      worksheet.getSemanticTypes().unassignColumnSemanticType(newType.getHNodeId());
    } else {
      worksheet.getSemanticTypes().addType(oldType);
      worksheet.getSemanticTypes().addSynonymTypesForHNodeId(newType.getHNodeId(), oldSynonymTypes);
    }

    // Replace the current alignment with the old alignment
    String alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
    AlignmentManager.Instance().addAlignmentToMap(alignmentId, oldAlignment);
View Full Code Here

    return CommandType.undoable;
  }

  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet wk = workspace.getWorksheet(worksheetId);
    UpdateContainer c = new UpdateContainer();
    SuperSelection selection = getSuperSelection(wk);
    // Get the HNode
    HNode hNode = workspace.getFactory().getHNode(hNodeId);
    columnName = hNode.getColumnName();
View Full Code Here

    return c;
  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    Worksheet wk = workspace.getWorksheet(worksheetId);
    SuperSelection selection = getSuperSelection(wk);
    if (splitCommaCommand != null)
      return splitCommaCommand.undoIt(workspace);
    RepFactory factory = workspace.getFactory();
    HNode hNode = factory.getHNode(newHNodeId);
View Full Code Here

      .getLogger(SampleDataFactory.class);

  public static Worksheet createSample1(Workspace workspace) {
    RepFactory f = workspace.getFactory();

    Worksheet w = f.createWorksheet("Complex Smaple Table", workspace, "UTF-8");
    String ss = w.addHNode("Social Security", HNodeType.Regular, f).getId();
    String personContainer = w.addHNode("Person", HNodeType.Regular, f).getId();
    String addressContainer = w.addHNode("Address", HNodeType.Regular, f).getId();
    String relativesContainer = w.addHNode("Relatives", HNodeType.Regular, f).getId();

    HTable personTable = w.getHeaders().getHNode(personContainer)
        .addNestedTable("Person Table", w, f);
    String firstName = personTable.addHNode("First Name", HNodeType.Regular, w, f).getId();
    String lastName = personTable.addHNode("Last Name", HNodeType.Regular, w, f).getId();

    HTable addressTable = w.getHeaders().getHNode(addressContainer)
        .addNestedTable("Address Table", w, f);
    String what = addressTable.addHNode("What", HNodeType.Regular, w, f).getId();
    String address = addressTable.addHNode("Address", HNodeType.Regular, w, f).getId();

    HTable relativesTable = w.getHeaders().getHNode(relativesContainer)
        .addNestedTable("Relatives Person Table", w, f);
    String relFirstName = relativesTable.addHNode("Relatives First Name", HNodeType.Regular,
        w, f).getId();
    String relLastName = relativesTable.addHNode("Relatives Last Name", HNodeType.Regular, w,
        f).getId();

    // Row 1
    Row r1 = w.addRow(f);
    r1.setValue(ss, "123-45-6789", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Pedro", f)
        .setValue(lastName, "Szekely", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Peter", f)
        .setValue(lastName, "Szekely", f);
    r1.addNestedRow(personContainer, f)
        .setValue(firstName, "P Alejandro", f)
        .setValue(lastName, "Szekely", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Pedro A", f)
        .setValue(lastName, "Szekely", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Pablo", f)
        .setValue(lastName, "Szekely", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Piotr", f)
        .setValue(lastName, "Szekely", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Peter", f)
        .setValue(lastName, "Szekeli", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Peter", f)
        .setValue(lastName, "CK Lee", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Peter", f)
        .setValue(lastName, "Zekely", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Peter", f)
        .setValue(lastName, "Zsekely", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Peter", f)
        .setValue(lastName, "Szeke", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Peter", f)
        .setValue(lastName, "Sequeli", f);
    r1.addNestedRow(addressContainer, f).setValue(what, "home", f)
        .setValue(address, "1401 E Maple Ave, El Segundo, CA 90245", f);
    r1.addNestedRow(addressContainer, f)
        .setValue(what, "work", f)
        .setValue(address,
            "4676 Admiralty Way #1000, Marina del Rey, CA 90292", f);
    r1.addNestedRow(relativesContainer, f)
        .setValue(relFirstName, "Claudia", f)
        .setValue(relLastName, "Szekely", f);
    r1.addNestedRow(relativesContainer, f)
        .setValue(relFirstName, "Susana", f)
        .setValue(relLastName, "Szekely", f);
    r1.addNestedRow(relativesContainer, f)
        .setValue(relFirstName, "Cristina", f)
        .setValue(relLastName, "Sierra", f);

    Row r2 = w.addRow(f);
    r2.setValue(ss, "007-00-7007", f);
    r2.addNestedRow(personContainer, f).setValue(firstName, "Shubham", f)
        .setValue(lastName, "Gupta", f);
    r2.addNestedRow(addressContainer, f)
        .setValue(what, "home", f)
View Full Code Here

  }

  public static Worksheet createSample1small(Workspace workspace) {
    RepFactory f = workspace.getFactory();

    Worksheet w = f.createWorksheet("Complex Smaple Table", workspace, "UTF-8");
    String ss = w.addHNode("Social Security", HNodeType.Regular, f).getId();
    String personContainer = w.addHNode("Person", HNodeType.Regular, f).getId();
    String addressContainer = w.addHNode("Address", HNodeType.Regular, f).getId();
    String relativesContainer = w.addHNode("Relatives", HNodeType.Regular, f).getId();

    HTable personTable = w.getHeaders().getHNode(personContainer)
        .addNestedTable("Person Table", w, f);
    String firstName = personTable.addHNode("First Name", HNodeType.Regular, w, f).getId();
    String lastName = personTable.addHNode("Last Name", HNodeType.Regular, w, f).getId();

    HTable addressTable = w.getHeaders().getHNode(addressContainer)
        .addNestedTable("Address Table", w, f);
    String what = addressTable.addHNode("What", HNodeType.Regular, w, f).getId();
    String address = addressTable.addHNode("Address", HNodeType.Regular, w, f).getId();

    HTable relativesTable = w.getHeaders().getHNode(relativesContainer)
        .addNestedTable("Relatives Person Table", w, f);
    String relFirstName = relativesTable.addHNode("Relatives First Name", HNodeType.Regular,
        w, f).getId();
    String relLastName = relativesTable.addHNode("Relatives Last Name", HNodeType.Regular, w,
        f).getId();

    // Row 1
    Row r1 = w.addRow(f);
    r1.setValue(ss, "123-45-6789", f);
    r1.addNestedRow(personContainer, f).setValue(firstName, "Pedro", f)
        .setValue(lastName, "Szekely", f);
    r1.addNestedRow(addressContainer, f).setValue(what, "home", f)
        .setValue(address, "1401 E Maple Ave", f);
View Full Code Here

  }

  public static Worksheet createFlatWorksheet(Workspace wsp, int numRows,
      int numColumns) {

    Worksheet w = wsp.getFactory().createWorksheet(
        "Table (" + numRows + ", " + numColumns + ")", wsp, "UTF-8");

    for (int c = 1; c <= numColumns; c++) {
      w.getHeaders().addHNode("Column " + c, HNodeType.Regular, w, wsp.getFactory());
    }

    int vCount = 1;
    for (int r = 1; r <= numRows; r++) {
      Row row = w.addRow(wsp.getFactory());
      for (HNode hn : w.getHeaders().getSortedHNodes()) {
        row.setValue(hn.getId(), "Value " + vCount, wsp.getFactory());
        vCount += 1;
      }
    }
View Full Code Here

TOP

Related Classes of edu.isi.karma.rep.Worksheet

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.