Hi Mehnaz,

This should do the job:

List<KIMAnnotation> annotations = new ArrayList<KIMAnnotation>(kimFilteredASet);
            Collections.sort(annotations, new Comparator<KIMAnnotation>() {
                public int compare(KIMAnnotation o1, KIMAnnotation o2) {
                    if (o1.getStartOffset() > o2.getEndOffset()) return 1;
else if (o1.getStartOffset() < o2.getEndOffset()) return -1;
                    else return 0;
                    // or just:
//                     return o1.getStartOffset() - o2.getStartOffset();
                }
            });


Greetings,
Philip


On 05/28/2010 07:07 AM, Mehnaz Adnan wrote:
Hi,
It is more like a java question than KIM, but would be grateful if anyone can help. I am annotating a string using KIM API using the code snippet below. It is creating the annotations and features but I want the annotations to sorted by 'id' or 'start'. Is there a easy way to get the KIMAnnotation in sorted order?

apiSemAnn.execute(kdocFromText);

KIMAnnotationSet kimASet = kdocFromText.getAnnotations();

Set typesSet = kimASet.getAllTypes();

Iterator iterator = typesSet.iterator();

*while* (iterator.hasNext()){

Object key = iterator.next();

KIMAnnotationSet kimFilteredASet = kimASet.get(String./valueOf/(key));

Iterator annIterator = kimFilteredASet.iterator();

System./out/.println("Annotations of type ["+String./valueOf/(key) + "] :");

*while* (annIterator.hasNext()){

KIMAnnotation kimAnnotation = (KIMAnnotation)annIterator.next();

System./out/.println(kimAnnotation.toString());

}

}


Thanks
--
Mehnaz


_______________________________________________
Kim-discussion mailing list
[email protected]
http://ontotext.com/mailman/listinfo/kim-discussion


--
Philip Alexiev<[email protected]>
Software Engineer
Ontotext AD

_______________________________________________
Kim-discussion mailing list
[email protected]
http://ontotext.com/mailman/listinfo/kim-discussion

Reply via email to