Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, December 10, 2019

Java data structure to use C implementation of word2vec

Data structure to use C implementation of word2vec. https://github.com/yfpeng/pengyifan-word2vec

Getting started






<dependency>
  <groupid>com.pengyifan.word2vec</groupid>
  <artifactid>pengyifan-word2vec</artifactid>
  <version>0.0.1</version>
</dependency>`
or
















<repositories>
    <repository>
        <id>oss-sonatype</id>
        <name>oss-sonatype</name>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
...
<dependency>
  <groupid>com.pengyifan.word2vec</groupid>
  <artifactid>pengyifan-word2vec</artifactid>
  <version>0.0.1-SNAPSHOT</version>
</dependency>

Webpage

The official word2vec webpage is available with all up-to-date instructions and code.

Thursday, September 5, 2013

When to use Comparable and Comparator?

By  | September 8, 2013

Programcreek demonstrates examples of using Comparable and Comparator. The next question will be when to use Comparable and Comparator. Here I list two basic rules (actually only the first one is really important):
  1. If there is a natural ordering of the object, then the class should implement Comparable, e.g., integers, strings (generally in the alphabet order), and points. On the other hand, if an object has multiple ways of ordering, then Comparator interface should be used to specify which way of sorting should take place. For example, HDTV in the Programcreek example can either be sorted by size or band name. In such case, Comparator is should be used. Another advantage is that Comparator can specify which parameter to be used for ordering. It then can be self descriptive. Hence, we can have SizeComparator and BandComparator for comparison, respectively.
  2. If you are not able to change the code of the object, which means you cannot implement Comparable, then Comparator is the only way left.
In summary, order of comparison is very important while implementing objects. Requirements may even change during implementing. For example, strings are generally compared alphabetically, but you may need to compare strings on their lengths as well. Therefore, designing of comparison needs to be very careful. In general, implement Comparable for natural order and write a Comparator for other needs.

Saturday, August 31, 2013

Top books for advanced level java developers


There are plenty of Java 101 books. But to those who have been using Java for several months or years, most of them may look too simple. However, advanced Java books are not always right at hand, not partially because they require more skills, experienced, and deep thinkers to write.

In this post, I would like to share my experience with only advanced level of Java, which means books like "Thinking in Java" or "Head First Java" won't be listed although they are very good for starters. Also I try to avoid listing Java books for specific software, frameworks or certifications, which I assume is not "pure" Java.

(This list will grow up gradually)

Java in a Nutshell

It is a more reference than a must read.

The elements of Java style

It is directed at anyone who writes Java code, by furnishing a set of rules for Java practitioners, by offering a collection of standards, conventions, and guidelines for writing solid Java code, and by illustrating how to write solid Java code that will be easy to understand, maintain, and enhance.

Effective Java

This book is really only for deeper understanding Java developer. It brings together seventy-eight indispensable programmer’s rules of thumb: working, best-practice solutions for the programming challenges you encounter every day.

The Java language specification

Written by the inventors of Java, this book not only provide complet and accurate converage of the language, but also includes formal rules of the language from the practical behavior of compilers. You may not get skills by reading it, but what if you want to cross the line and crack Java VM...

Design patterns: elements of reusableobject-oriented software

Actually, examples in this book were written in C++ or smalltalk, but so what? If you want to grow as a developer, you have know Design Patterns, to take advantages of the best practices and experience of others, and learn from those who have face the same problems. There are many other similar books, but they are just doing patching work.

The Pragmatic Programmer: From Journeyman to Master

Again, it is not a book for Java developer only. "The cool thing about this book is that it's great for keeping the programming process fresh. The book helps you to continue to grow and clearly comes from people who have been there."

Sunday, April 21, 2013

Ignoring DTD in XMLUnit


@BeforeClass
public static void onlyOnce() {

 XMLUnit.setIgnoreWhitespace(true);
 XMLUnit.setIgnoreComments(true);
 XMLUnit.setIgnoreAttributeOrder(true);

 // don't validate dtd
 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 dbf.setValidating(false);
 try {
   dbf.setFeature("http://xml.org/sax/features/namespaces", false);
   dbf.setFeature("http://xml.org/sax/features/validation", false);
   dbf.setFeature(
       "http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
       false);
   dbf.setFeature(
       "http://apache.org/xml/features/nonvalidating/load-external-dtd",
       false);
 } catch (ParserConfigurationException e) {
   e.printStackTrace();
 }

 XMLUnit.setTestDocumentBuilderFactory(dbf);
 XMLUnit.setControlDocumentBuilderFactory(dbf);
}