Java Code Examples for java.io.InvalidClassException#printStackTrace()

The following examples show how to use java.io.InvalidClassException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageManager.java    From LoboBrowser with MIT License 6 votes vote down vote up
public Serializable retrieveSettings(final String name, final ClassLoader classLoader) throws IOException, ClassNotFoundException {
  final File dir = this.getSettingsDirectory();
  if (!dir.exists()) {
    return null;
  }
  final File file = new File(dir, name);
  if (!file.exists()) {
    return null;
  }
  try (
      final InputStream in = new FileInputStream(file);
      final BufferedInputStream bin = new BufferedInputStream(in);
      final ObjectInputStream ois = new ClassLoaderObjectInputStream(bin, classLoader)) {
    return (Serializable) ois.readObject();
  } catch (final InvalidClassException ice) {
    ice.printStackTrace();
    return null;
  }
}
 
Example 2
Source File: SingleLinkClusterer.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Calculates the similarity between two clusters. In this algorithm the 
 * maximum similarity over all pairs of the two clusters is used.
 *@param sClusterOne The first cluster.
 *@param sClusterTwo The second cluster.
 *@param clDistanceCalculator The calculator of distance between set elements.
 *@return The similarity between the clusters.
 */
protected double getSimilarityBetweenClusters(Set sClusterOne, Set sClusterTwo, 
        SimilarityComparatorListener clDistanceCalculator) {
    Distribution dDistances = new Distribution();
    
    // For every object in cluster one
    Iterator iFirstCluster = sClusterOne.iterator();
    int iCnt = 0;
    
    while (iFirstCluster.hasNext()) {
        Object oFirst = iFirstCluster.next();

        // For every object in cluster two
        Iterator iSecondCluster = sClusterTwo.iterator();
        while (iSecondCluster.hasNext()) {
            Object oSecond = iSecondCluster.next();
            ISimilarity sSimil;
            // Compare the objects
            try {
                synchronized (oFirst) {
                    synchronized (oSecond) {
                        sSimil = clDistanceCalculator.getSimilarityBetween(oFirst, 
                                oSecond);
                    }
                }
            } catch (InvalidClassException ex) {
                System.err.println("Cannot compare " + oFirst.toString() + " to " + 
                        oSecond.toString() + ". Cause:");
                ex.printStackTrace(System.err);
                continue;
            }
            // Put id of pair and their similarity in distance distribution
            dDistances.setValue(iCnt++, sSimil.getOverallSimilarity());                    
        }
    }
    
    // Return the maximum similarity
    return dDistances.maxValue();
}
 
Example 3
Source File: AverageLinkClusterer.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Calculates the similarity between two clusters. In this algorithm the 
 * average similarity between all pairs of the two clusters is used.
 *@param sClusterOne The first cluster.
 *@param sClusterTwo The second cluster.
 *@param clDistanceCalculator The calculator of distance between set elements.
 *@return The similarity between the clusters.
 */
protected double getSimilarityBetweenClusters(Set sClusterOne, Set sClusterTwo, 
        SimilarityComparatorListener clDistanceCalculator) {
    Distribution dDistances = new Distribution();
    
    // For every object in cluster one
    Iterator iFirstCluster = sClusterOne.iterator();
    int iCnt = 0;
    while (iFirstCluster.hasNext()) {
        Object oFirst = iFirstCluster.next();

        // For every object in cluster two
        Iterator iSecondCluster = sClusterTwo.iterator();
        while (iSecondCluster.hasNext()) {
            Object oSecond = iSecondCluster.next();
            ISimilarity sSimil;
            // Compare the objects
            try {
                synchronized (oFirst) {
                    synchronized (oSecond) {
                        sSimil = clDistanceCalculator.getSimilarityBetween(oFirst, 
                                oSecond);
                    }
                }
            } catch (InvalidClassException ex) {
                System.err.println("Cannot compare " + oFirst.toString() + " to " + 
                        oSecond.toString() + ". Cause:");
                ex.printStackTrace(System.err);
                continue;
            }
            // Put id of pair and their similarity in distance distribution
            dDistances.setValue(iCnt++, sSimil.getOverallSimilarity());                    
        }
    }
    
    // Return the maximum similarity, which is actually the average of distance between elements.
    return dDistances.average(true);
}
 
Example 4
Source File: CompleteLinkClusterer.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Calculates the similarity between two clusters. In this algorithm the 
 * minimum similarity between all pairs of the two clusters is used.
 *@param sClusterOne The first cluster.
 *@param sClusterTwo The second cluster.
 *@param clDistanceCalculator The calculator of distance between set elements.
 *@return The similarity between the clusters.
 */
protected double getSimilarityBetweenClusters(Set sClusterOne, Set sClusterTwo, 
        SimilarityComparatorListener clDistanceCalculator) {
    Distribution dDistances = new Distribution();
    
    // For every object in cluster one
    Iterator iFirstCluster = sClusterOne.iterator();
    int iCnt = 0;
    while (iFirstCluster.hasNext()) {
        Object oFirst = iFirstCluster.next();

        // For every object in cluster two
        Iterator iSecondCluster = sClusterTwo.iterator();
        while (iSecondCluster.hasNext()) {
            Object oSecond = iSecondCluster.next();
            ISimilarity sSimil;
            // Compare the objects
            try {
                sSimil = clDistanceCalculator.getSimilarityBetween(oFirst, oSecond);
            } catch (InvalidClassException ex) {
                System.err.println("Cannot compare " + oFirst.toString() + " to " + 
                        oSecond.toString() + ". Cause:");
                ex.printStackTrace(System.err);
                continue;
            }
            // Put id of pair and their similarity in distance distribution
            dDistances.setValue(iCnt++, sSimil.getOverallSimilarity());                    
        }
    }
    
    // Return the maximum similarity
    return dDistances.minValue();
}
 
Example 5
Source File: SingleLinkClusterer.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Calculates the similarity between two clusters. In this algorithm the 
 * maximum similarity over all pairs of the two clusters is used.
 *@param sClusterOne The first cluster.
 *@param sClusterTwo The second cluster.
 *@param clDistanceCalculator The calculator of distance between set elements.
 *@return The similarity between the clusters.
 */
protected double getSimilarityBetweenClusters(Set sClusterOne, Set sClusterTwo, 
        SimilarityComparatorListener clDistanceCalculator) {
    Distribution dDistances = new Distribution();
    
    // For every object in cluster one
    Iterator iFirstCluster = sClusterOne.iterator();
    int iCnt = 0;
    
    while (iFirstCluster.hasNext()) {
        Object oFirst = iFirstCluster.next();

        // For every object in cluster two
        Iterator iSecondCluster = sClusterTwo.iterator();
        while (iSecondCluster.hasNext()) {
            Object oSecond = iSecondCluster.next();
            ISimilarity sSimil;
            // Compare the objects
            try {
                synchronized (oFirst) {
                    synchronized (oSecond) {
                        sSimil = clDistanceCalculator.getSimilarityBetween(oFirst, 
                                oSecond);
                    }
                }
            } catch (InvalidClassException ex) {
                System.err.println("Cannot compare " + oFirst.toString() + " to " + 
                        oSecond.toString() + ". Cause:");
                ex.printStackTrace(System.err);
                continue;
            }
            // Put id of pair and their similarity in distance distribution
            dDistances.setValue(iCnt++, sSimil.getOverallSimilarity());                    
        }
    }
    
    // Return the maximum similarity
    return dDistances.maxValue();
}
 
Example 6
Source File: AverageLinkClusterer.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Calculates the similarity between two clusters. In this algorithm the 
 * average similarity between all pairs of the two clusters is used.
 *@param sClusterOne The first cluster.
 *@param sClusterTwo The second cluster.
 *@param clDistanceCalculator The calculator of distance between set elements.
 *@return The similarity between the clusters.
 */
protected double getSimilarityBetweenClusters(Set sClusterOne, Set sClusterTwo, 
        SimilarityComparatorListener clDistanceCalculator) {
    Distribution dDistances = new Distribution();
    
    // For every object in cluster one
    Iterator iFirstCluster = sClusterOne.iterator();
    int iCnt = 0;
    while (iFirstCluster.hasNext()) {
        Object oFirst = iFirstCluster.next();

        // For every object in cluster two
        Iterator iSecondCluster = sClusterTwo.iterator();
        while (iSecondCluster.hasNext()) {
            Object oSecond = iSecondCluster.next();
            ISimilarity sSimil;
            // Compare the objects
            try {
                synchronized (oFirst) {
                    synchronized (oSecond) {
                        sSimil = clDistanceCalculator.getSimilarityBetween(oFirst, 
                                oSecond);
                    }
                }
            } catch (InvalidClassException ex) {
                System.err.println("Cannot compare " + oFirst.toString() + " to " + 
                        oSecond.toString() + ". Cause:");
                ex.printStackTrace(System.err);
                continue;
            }
            // Put id of pair and their similarity in distance distribution
            dDistances.setValue(iCnt++, sSimil.getOverallSimilarity());                    
        }
    }
    
    // Return the maximum similarity, which is actually the average of distance between elements.
    return dDistances.average(true);
}
 
Example 7
Source File: CompleteLinkClusterer.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Calculates the similarity between two clusters. In this algorithm the 
 * minimum similarity between all pairs of the two clusters is used.
 *@param sClusterOne The first cluster.
 *@param sClusterTwo The second cluster.
 *@param clDistanceCalculator The calculator of distance between set elements.
 *@return The similarity between the clusters.
 */
protected double getSimilarityBetweenClusters(Set sClusterOne, Set sClusterTwo, 
        SimilarityComparatorListener clDistanceCalculator) {
    Distribution dDistances = new Distribution();
    
    // For every object in cluster one
    Iterator iFirstCluster = sClusterOne.iterator();
    int iCnt = 0;
    while (iFirstCluster.hasNext()) {
        Object oFirst = iFirstCluster.next();

        // For every object in cluster two
        Iterator iSecondCluster = sClusterTwo.iterator();
        while (iSecondCluster.hasNext()) {
            Object oSecond = iSecondCluster.next();
            ISimilarity sSimil;
            // Compare the objects
            try {
                sSimil = clDistanceCalculator.getSimilarityBetween(oFirst, oSecond);
            } catch (InvalidClassException ex) {
                System.err.println("Cannot compare " + oFirst.toString() + " to " + 
                        oSecond.toString() + ". Cause:");
                ex.printStackTrace(System.err);
                continue;
            }
            // Put id of pair and their similarity in distance distribution
            dDistances.setValue(iCnt++, sSimil.getOverallSimilarity());                    
        }
    }
    
    // Return the maximum similarity
    return dDistances.minValue();
}
 
Example 8
Source File: SimilarityBasedIndex.java    From Ngram-Graphs with Apache License 2.0 4 votes vote down vote up
/** Returns the set of documents of the cluster that is most appropriate,
 * given a document graph.
 *@param dngCur The graph of the document used.
 *@return A {@link Set} of strings, corresponding to the document IDs in the
 *cluster that has the most similar content to the given document.
 */
@Override
public Set<String> locateSimilarDocuments(DocumentNGramGraph dngCur) {
    String sClusterLabel = null;
    // Init similarity to low value
    double dSim = 0.0;
    double dPrvSim = 0.0;
                    
    // Remove grammar
    //if (Grammar != null)
    //  dgCur = dgCur.allNotIn(Grammar);
    
    // Init current cluster to top
    Vertex vBestCandidate = null;
    Vertex vCur = getRootHierarchyNode(Hierarchy);
    
    // DEBUG LINES
    // Store index path
    LinkedList<String> lPath = new LinkedList<String>();
    lPath.add(vCur.getLabel());
    //////////////
    do {
        dPrvSim = dSim;
        
        // Get similarity of all childen of the current node to given doc
        Iterator iChildren = utils.getAdjacentIncomingVertices(Hierarchy, 
                vCur).iterator();
        vBestCandidate = vCur; // Best candidate is the current vertex
        
        // If not reached leaf
        if (iChildren.hasNext())
        {                
            // For every child
            while (iChildren.hasNext()) {
                Vertex vCandidate = (Vertex)iChildren.next();
                double dCurSim = Double.NEGATIVE_INFINITY;
                try {
                    // DEBUG LINES
                    // System.out.println("Comparing to..." + vCandidate.getLabel());
                    //////////////
                    
                    // Init comparator if required
                    initComparator();
                    dCurSim = Comparator.getSimilarityBetween(
                            dngCur, 
                            getRepresentationFromCluster(vCandidate.getLabel())).getOverallSimilarity();
                } catch (InvalidClassException ex) {
                    System.err.println("Invalid document type. Ignoring...");
                    ex.printStackTrace(System.err);
                }
                // If candidate is more similar than the parent
                if (dCurSim > dSim)
                {
                    // Update best candidate
                    vBestCandidate = vCandidate;
                    // and similarity
                    dSim = dCurSim;
                }
            }
        }
        
        vCur = vBestCandidate; // Update current position
        sClusterLabel = vBestCandidate.getLabel(); // Update best cluster label
        // DEBUG LINES
        // Add current node to path
        lPath.add(sClusterLabel);
        //////////////
    } while (dPrvSim < dSim);
    
    // DEBUG LINES
    System.err.println(utils.printIterable(lPath, "->\n"));
    //////////////
    return getDocumentIDsFromCluster(sClusterLabel);
}
 
Example 9
Source File: SimilarityBasedIndex.java    From Ngram-Graphs with Apache License 2.0 4 votes vote down vote up
/** Returns the set of documents of the cluster that is most appropriate,
 * given a document graph.
 *@param dngCur The graph of the document used.
 *@return A {@link Set} of strings, corresponding to the document IDs in the
 *cluster that has the most similar content to the given document.
 */
@Override
public Set<String> locateSimilarDocuments(DocumentNGramGraph dngCur) {
    String sClusterLabel = null;
    // Init similarity to low value
    double dSim = 0.0;
    double dPrvSim = 0.0;
                    
    // Remove grammar
    //if (Grammar != null)
    //  dgCur = dgCur.allNotIn(Grammar);
    
    // Init current cluster to top
    Vertex vBestCandidate = null;
    Vertex vCur = getRootHierarchyNode(Hierarchy);
    
    // DEBUG LINES
    // Store index path
    LinkedList<String> lPath = new LinkedList<String>();
    lPath.add(vCur.getLabel());
    //////////////
    do {
        dPrvSim = dSim;
        
        // Get similarity of all childen of the current node to given doc
        Iterator iChildren = utils.getAdjacentIncomingVertices(Hierarchy, 
                vCur).iterator();
        vBestCandidate = vCur; // Best candidate is the current vertex
        
        // If not reached leaf
        if (iChildren.hasNext())
        {                
            // For every child
            while (iChildren.hasNext()) {
                Vertex vCandidate = (Vertex)iChildren.next();
                double dCurSim = Double.NEGATIVE_INFINITY;
                try {
                    // DEBUG LINES
                    // System.out.println("Comparing to..." + vCandidate.getLabel());
                    //////////////
                    
                    // Init comparator if required
                    initComparator();
                    dCurSim = Comparator.getSimilarityBetween(
                            dngCur, 
                            getRepresentationFromCluster(vCandidate.getLabel())).getOverallSimilarity();
                } catch (InvalidClassException ex) {
                    System.err.println("Invalid document type. Ignoring...");
                    ex.printStackTrace(System.err);
                }
                // If candidate is more similar than the parent
                if (dCurSim > dSim)
                {
                    // Update best candidate
                    vBestCandidate = vCandidate;
                    // and similarity
                    dSim = dCurSim;
                }
            }
        }
        
        vCur = vBestCandidate; // Update current position
        sClusterLabel = vBestCandidate.getLabel(); // Update best cluster label
        // DEBUG LINES
        // Add current node to path
        lPath.add(sClusterLabel);
        //////////////
    } while (dPrvSim < dSim);
    
    // DEBUG LINES
    System.err.println(utils.printIterable(lPath, "->\n"));
    //////////////
    return getDocumentIDsFromCluster(sClusterLabel);
}