/**
   * Start at the given nesting level - read lines until you get to line with equal to or greater
   * than the current one.
   */
  public static String[] getArtifactLines(Pointer startingIndex, String... lines) {
    List<String> lineList = new ArrayList<>();
    int index = startingIndex.getIndex();
    String topLine = lines[index];

    lineList.add(
        topLine); // add the line which defines this object - all others, if they exist, are
                  // children.

    int nestingLevel = parseNestingLevel(topLine);

    for (int i = index + 1; i < lines.length; i++) {
      String line = lines[i];

      // we return if the nesting level of the line in question is the same as the "parent" level
      int childNestingLevel = parseNestingLevel(line);

      if (childNestingLevel == nestingLevel) {
        startingIndex.increment(lineList.size());

        // return new array of startIndex to i
        return lineList.toArray(new String[lineList.size()]);
      } else {
        lineList.add(line);
      }
    }

    startingIndex.increment(lineList.size());

    return lineList.toArray(new String[lineList.size()]);
  }
Beispiel #2
0
 private void checkPointers() {
   if (null != dictionary && dictionary.getCheckAlienPointers() && !checkingPointers) {
     synchronized (this) {
       checkingPointers = true;
       if (null != dictionary && dictionary.isEditable()) {
         List<Pointer> toDelete = null;
         for (int i = 0; i < super.size(); i++) {
           Pointer pointer = super.get(i);
           if (dictionary != pointer.getSource().getDictionary()
               || null == pointer.getTarget()
               || dictionary != pointer.getTarget().getDictionary()) {
             if (null == toDelete) {
               toDelete = new ArrayList<Pointer>();
             }
             toDelete.add(pointer);
           }
         }
         if (null != toDelete) {
           if (log.isWarnEnabled() && 0 < toDelete.size()) {
             log.warn(JWNL.resolveMessage("DICTIONARY_WARN_002", Synset.this.getOffset()));
           }
           for (Pointer pointer : toDelete) {
             remove(pointer);
           }
         }
       }
       checkingPointers = false;
     }
   }
 }
 private static Set<Long> findAdverbAntonyms(Dictionary dic) throws SMatchException {
   log.info("Creating adverb antonyms array...");
   try {
     Set<Long> keys = new HashSet<>();
     int count = 0;
     Iterator<Synset> it = dic.getSynsetIterator(POS.ADVERB);
     while (it.hasNext()) {
       count++;
       if (0 == count % 1000) {
         log.debug("adverb antonyms: " + count);
       }
       Synset source = it.next();
       long sourceOffset = source.getOffset();
       List<Pointer> pointers = source.getPointers(PointerType.ANTONYM);
       for (Pointer ptr : pointers) {
         long targetOffset = ptr.getTargetOffset();
         long key;
         if (targetOffset > sourceOffset) {
           key = (targetOffset << 32) + sourceOffset;
         } else {
           key = (sourceOffset << 32) + targetOffset;
         }
         keys.add(key);
       }
     }
     log.info("Adverbs antonyms: " + keys.size());
     return keys;
   } catch (JWNLException e) {
     throw new SMatchException(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
   }
 }
 private static Set<Long> findNominalizations(Dictionary dic) throws SMatchException {
   log.info("Creating nominalizations array...");
   try {
     Set<Long> keys = new HashSet<>();
     int count = 0;
     Iterator<Synset> it = dic.getSynsetIterator(POS.VERB);
     while (it.hasNext()) {
       count++;
       if (0 == count % 1000) {
         log.debug("nominalizations: " + count);
       }
       Synset source = it.next();
       List<Pointer> pointers = source.getPointers(PointerType.DERIVATION);
       for (Pointer pointer : pointers) {
         if (POS.NOUN.equals(pointer.getTargetPOS())) {
           long targetOffset = pointer.getTargetOffset();
           long key = (source.getOffset() << 32) + targetOffset;
           keys.add(key);
         }
       }
     }
     log.info("Nominalizations: " + keys.size());
     return keys;
   } catch (JWNLException e) {
     throw new SMatchException(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
   }
 }
Beispiel #5
0
 @Override
 public boolean retainAll(Collection<?> c) {
   if (null != dictionary && dictionary.isEditable()) {
     List<Pointer> copy = new ArrayList<Pointer>(this);
     boolean result = super.retainAll(c);
     for (Object object : c) {
       if (object instanceof Pointer) {
         Pointer pointer = (Pointer) object;
         if (!copy.contains(pointer)) {
           // delete symmetric pointer from the target
           if (null != pointer.getType().getSymmetricType()
               && dictionary.getManageSymmetricPointers()) {
             for (Pointer p : pointer.getTargetSynset().getPointers()) {
               if (offset == p.getTargetOffset()
                   && pointer.getType().getSymmetricType().equals(p.getType())) {
                 pointer.getTargetSynset().getPointers().remove(p);
                 break;
               }
             }
           }
         }
       }
     }
     return result;
   } else {
     return super.retainAll(c);
   }
 }
 private static void cartPr(Set<Long> keys, List<Pointer> t) throws JWNLException {
   for (int i = 0; i < t.size(); i++) {
     Pointer ps = t.get(i);
     long sourceOffset = ps.getTargetSynset().getOffset();
     for (int j = i + 1; j < t.size(); j++) {
       Pointer pt = t.get(j);
       long targetOffset = pt.getTargetSynset().getOffset();
       if (sourceOffset != targetOffset) {
         long key;
         if (targetOffset > sourceOffset) {
           key = (targetOffset << 32) + sourceOffset;
         } else {
           key = (sourceOffset << 32) + targetOffset;
         }
         keys.add(key);
       }
     }
   }
 }
Beispiel #7
0
 @Override
 public boolean remove(Object o) {
   boolean result = super.remove(o);
   if (null != dictionary
       && dictionary.isEditable()
       && dictionary.getManageSymmetricPointers()
       && o instanceof Pointer) {
     Pointer pointer = (Pointer) o;
     // delete symmetric pointer from the target
     if (null != pointer.getType().getSymmetricType()) {
       if (null != pointer.getTargetSynset()) {
         for (Pointer p : pointer.getTargetSynset().getPointers()) {
           if (offset == p.getTargetOffset()
               && pointer.getType().getSymmetricType().equals(p.getType())) {
             pointer.getTargetSynset().getPointers().remove(p);
             break;
           }
         }
       }
     }
   }
   return result;
 }
Beispiel #8
0
 @Override
 public Pointer remove(int index) {
   Pointer result = super.remove(index);
   if (null != dictionary
       && dictionary.isEditable()
       && dictionary.getManageSymmetricPointers()) {
     // delete symmetric pointer from the target
     Pointer pointer = get(index);
     if (null != pointer.getType().getSymmetricType()) {
       for (Pointer p : pointer.getTargetSynset().getPointers()) {
         if (offset == p.getTargetOffset()
             && pointer.getType().getSymmetricType().equals(p.getType())) {
           pointer.getTargetSynset().getPointers().remove(p);
           break;
         }
       }
     }
   }
   return result;
 }
Beispiel #9
0
 @Override
 protected void removeRange(int fromIndex, int toIndex) {
   if (null != dictionary && dictionary.isEditable()) {
     List<Pointer> copy = new ArrayList<Pointer>(super.subList(fromIndex, toIndex));
     super.removeRange(fromIndex, toIndex);
     for (Pointer pointer : copy) {
       // delete symmetric pointer from the target
       if (null != pointer.getType().getSymmetricType()
           && dictionary.getManageSymmetricPointers()) {
         for (Pointer p : pointer.getTargetSynset().getPointers()) {
           if (offset == p.getTargetOffset()
               && pointer.getType().getSymmetricType().equals(p.getType())) {
             pointer.getTargetSynset().getPointers().remove(p);
             break;
           }
         }
       }
     }
   } else {
     super.removeRange(fromIndex, toIndex);
   }
 }
Beispiel #10
0
 @Override
 public void clear() {
   if (null != dictionary && dictionary.isEditable()) {
     List<Pointer> copy = new ArrayList<Pointer>(this);
     super.clear();
     for (Pointer pointer : copy) {
       // delete symmetric pointer from the target
       if (null != pointer.getType().getSymmetricType()
           && dictionary.getManageSymmetricPointers()) {
         for (Pointer p : pointer.getTargetSynset().getPointers()) {
           if (offset == p.getTargetOffset()
               && pointer.getType().getSymmetricType().equals(p.getType())) {
             pointer.getTargetSynset().getPointers().remove(p);
             break;
           }
         }
       }
     }
   } else {
     super.clear();
   }
 }
Beispiel #11
0
    @Override
    public void add(int index, Pointer pointer) {
      if (null == pointer) {
        throw new IllegalArgumentException(JWNL.resolveMessage("DICTIONARY_EXCEPTION_043"));
      }
      super.add(index, pointer);

      if (null != dictionary
          && dictionary.isEditable()
          && dictionary.getManageSymmetricPointers()) {
        if (null != pointer.getType().getSymmetricType()) {
          Pointer symmetric =
              new Pointer(
                  pointer.getType().getSymmetricType(), pointer.getTarget(), pointer.getSource());
          if (!pointer.getTarget().getSynset().getPointers().contains(symmetric)) {
            pointer.getTarget().getSynset().getPointers().add(symmetric);
          }
        }
      }
    }