package semantics.model;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Set;
import semantics.KnowBase;


public final class Individual implements Comparable<Individual> {
  private final KnowBase kb;
  private final String   iri;

  public Individual(KnowBase kb, String iri) {
    this.kb  = kb;
    this.iri = iri;
  }


  public KnowBase getKnowBase() {
    return kb;
  }

  public String getIri() {
    return iri;
  }

  public String getName() {
    // FIXME: URIs aren't exactly IRIs, since they don't allow Unicode
    // characters. This either needs URL encoding or a real IRI library.
    try {
      return new URI(iri).getFragment();
    }
    catch (URISyntaxException e) {
      return iri;
    }
  }


  @Override
  public String toString() {
    return getIri();
  }

  @Override
  public boolean equals(Object other) {
    if (other instanceof Individual) {
      Individual i = (Individual) other;
      return kb.equals(i.kb) && iri.equals(i.iri);
    }
    return false;
  }

  @Override
  public int hashCode() {
    return (kb + "\0" + iri).hashCode();
  }


  public int compareTo(Individual other) {
    return getIri().compareTo(other.getIri());
  }
}

@@ -131,327 +131,1265 @@
 ;%0A%0A%0A
-public final class Individual implements Comparable%3CIndividual%3E %7B%0A  private final KnowBase kb;%0A  private final String   iri;%0A%0A  public Individual(KnowBase kb, String iri) %7B%0A    this.kb  = kb;%0A    this.iri = iri;%0A  %7D%0A%0A%0A  public KnowBase getKnowBase() %7B%0A    return kb;%0A  %7D%0A%0A  public String getIri() %7B%0A    return iri;%0A  %7D%0A
+/**%0A * An individual, retrieved via querying or projection.%0A *%0A * This represents an individual from a knowledge base. It's basically just an%0A * identity built from a knowledge base and an IRI string. But don't mess with%0A * the knowledge base part directly.%0A */%0Apublic final class Individual implements Comparable%3CIndividual%3E %7B%0A  private final KnowBase kb;%0A  private final String   iri;%0A%0A  /**%0A   * Internal, don't use.%0A   *%0A   * Get your individuals by querying, don't construct them yourself.%0A   */%0A  public Individual(KnowBase kb, String iri) %7B%0A    this.kb  = kb;%0A    this.iri = iri;%0A  %7D%0A%0A%0A  /**%0A   * This individual's knowledge base, for identity.%0A   *%0A   * But don't use it for anything other than checking the identity of the%0A   * knowledge base, all the knowledge base functions are internal-only.%0A   */%0A  public KnowBase getKnowBase() %7B%0A    return kb;%0A  %7D%0A%0A  /**%0A   * This individual's IRI.%0A   *%0A   * That's an Internationalized Resource Identifier, similar to a URL.%0A   */%0A  public String getIri() %7B%0A    return iri;%0A  %7D%0A%0A  /**%0A   * Tries to extract the fragment part from the IRI.%0A   *%0A   * You can use this to display individuals to the user. If for some reason%0A   * the fragment part can't be figured out, you'll get the entire IRI instead.%0A   */
 %0A  p
@@ -2042,16 +2042,27 @@
 );%0A  %7D%0A%0A
+  @Override
 %0A  publi

Document Individual, since it's public API