Difference between revisions of "Concept:Person/Java"

From BITPlan royal-family Wiki
Jump to navigation Jump to search
m (created by WikiTask 2017-10-10T06:13:36Z)
m (created by WikiTask 2017-10-10T08:45:13Z)
Line 37: Line 37:
  
 
     /**
 
     /**
     * get the propertySidif of the given property
+
     * get the SiDIF representation of the given property
 
     *  
 
     *  
     * @param name
+
     * @param name - the name of the property
     * @param value
+
     * @param value - the value of the property
     * @return
+
    * @param type - the type of the property
 +
     * @return - the SiDIF Sting representation of the property
 
     */
 
     */
 
     public static String propertySiDIF(String name, String value, String type) {
 
     public static String propertySiDIF(String name, String value, String type) {
       // default is an empty string - no property line for emtpy values
+
       // default is a comment line which can be filled by uncommenting
       String result = "";
+
       String result = String.format("# is is %s of it\n",name);;
 
       // if the value is not empty
 
       // if the value is not empty
 
       if ((value != null) && (!("".equals(value.trim())))) {
 
       if ((value != null) && (!("".equals(value.trim())))) {
Line 56: Line 57:
 
         // create a SIDIF Property line like
 
         // create a SIDIF Property line like
 
         // "John" is lastname of it
 
         // "John" is lastname of it
         result += quote + value + quote + " is " + name + " of it\n";
+
         result = String.format("%s%s%s is %s of it\n",quote,value,quote,name);
 
       }
 
       }
 
       // return the SiDIF property line
 
       // return the SiDIF property line
Line 133: Line 134:
 
     /**
 
     /**
 
     * convert this Family to a WikiSon string
 
     * convert this Family to a WikiSon string
 +
    * @return the WikiSon representation of this Family
 
     */
 
     */
 
     public String toWikiSon() {
 
     public String toWikiSon() {
Line 146: Line 148:
 
       wikison+="}}\n";
 
       wikison+="}}\n";
 
       return wikison;
 
       return wikison;
 +
    }
 +
 +
/**
 +
    * convert this Family to a SiDIF string
 +
    * @return the SiDIF representation of this Family
 +
    */
 +
    public String toSiDIF() {
 +
      String siDIF = String.format("%s isA Family\n",this.pageid);
 +
      siDIF+=propertySiDIF("name",name,Text);
 +
      siDIF+=propertySiDIF("weddingDate",weddingDate,Date);
 +
      siDIF+=propertySiDIF("weddingPlace",weddingPlace,Text);
 +
      siDIF+=propertySiDIF("yearMarried",yearMarried,Number);
 +
      siDIF+=propertySiDIF("monthMarried",monthMarried,Number);
 +
      siDIF+=propertySiDIF("divorced",divorced,Date);
 +
      siDIF+=propertySiDIF("husbandOf",husbandOf,Page);
 +
      siDIF+=propertySiDIF("wifeOf",wifeOf,Page);
 +
      return siDIF;
 
     }
 
     }
 
   
 
   
Line 370: Line 389:
 
     /**
 
     /**
 
     * convert this Person to a WikiSon string
 
     * convert this Person to a WikiSon string
 +
    * @return the WikiSon representation of this Person
 
     */
 
     */
 
     public String toWikiSon() {
 
     public String toWikiSon() {
Line 394: Line 414:
 
       wikison+="}}\n";
 
       wikison+="}}\n";
 
       return wikison;
 
       return wikison;
 +
    }
 +
 +
/**
 +
    * convert this Person to a SiDIF string
 +
    * @return the SiDIF representation of this Person
 +
    */
 +
    public String toSiDIF() {
 +
      String siDIF = String.format("%s isA Person\n",this.pageid);
 +
      siDIF+=propertySiDIF("qid",qid,Text);
 +
      siDIF+=propertySiDIF("royal92id",royal92id,Text);
 +
      siDIF+=propertySiDIF("name",name,Text);
 +
      siDIF+=propertySiDIF("nobleTitle",nobleTitle,Text);
 +
      siDIF+=propertySiDIF("picture",picture,URL);
 +
      siDIF+=propertySiDIF("sex",sex,Text);
 +
      siDIF+=propertySiDIF("born",born,Date);
 +
      siDIF+=propertySiDIF("yearBorn",yearBorn,Number);
 +
      siDIF+=propertySiDIF("monthBorn",monthBorn,Number);
 +
      siDIF+=propertySiDIF("birthPlace",birthPlace,Text);
 +
      siDIF+=propertySiDIF("died",died,Date);
 +
      siDIF+=propertySiDIF("diedAt",diedAt,Text);
 +
      siDIF+=propertySiDIF("yearDied",yearDied,Number);
 +
      siDIF+=propertySiDIF("monthDied",monthDied,Number);
 +
      siDIF+=propertySiDIF("noInLine",noInLine,Number);
 +
      siDIF+=propertySiDIF("wikiPedia",wikiPedia,URL);
 +
      siDIF+=propertySiDIF("childOf",childOf,Page);
 +
      siDIF+=propertySiDIF("parentOf",parentOf,Page);
 +
      siDIF+=propertySiDIF("spouse",spouse,Page);
 +
      return siDIF;
 
     }
 
     }
 
   
 
   

Revision as of 10:45, 10 October 2017

java code

@// This is a rythm template
@// the args are the standard wikiTask arguments
@import org.sidif.triple.TripleQuery
@import org.sidif.triple.Triple
@import com.alibaba.fastjson.JSON
@args() {
  String title 
  String logo
  org.sidif.wiki.WikiTask wikiTask
  org.sidif.triple.TripleStore tripleStore
}


@def static {

  /**
   * Base class
   */
  static abstract class TopicBase {
    // each Topic has a pageid - for non subobject thats the pagename
    public String pageid;

    /**
     * get a WikiSon version of the given name value
     * 
     * @param name
     * @param value
     * @return - the string representation
     */
    public String toWikiSon(String name, String value) {
      String result = "<!-- " + name + " is null-->\n";
      if (value != null)
        result = "|" + name + "=" + value + "\n";
      return result;
    }

    /**
     * get the SiDIF representation of the given property
     * 
     * @param name - the name of the property
     * @param value - the value of the property
     * @param type - the type of the property
     * @return - the SiDIF Sting representation of the property
     */
    public static String propertySiDIF(String name, String value, String type) {
      // default is a comment line which can be filled by uncommenting
      String result = String.format("# is is %s of it\n",name);;
      // if the value is not empty
      if ((value != null) && (!("".equals(value.trim())))) {
        // do we need to quote the result?
        String quote = "";
        // this depends on the Type
        if ("Text".equals(type)) {
          quote = "\"";
        }
        // create a SIDIF Property line like
        // "John" is lastname of it
        result = String.format("%s%s%s is %s of it\n",quote,value,quote,name);
      }
      // return the SiDIF property line
      return result;
    }

    /**
     * get me as a String
     * 
     * @param name
     * @param value
     * @return
     */
    public static String propertySiDIF(String name, String value) {
      String result = propertySiDIF(name, value, "Text");
      return result;
    }

    /**
     * check if the given boolean String value is true
     * 
     * @param value
     * @return true if the value is not null and has true/TRUE as it's string
     *         content
     */
    public boolean isTrue(String value) {
      boolean result = false;
      if (value != null && value.toLowerCase().equals("true")) {
        result = true;
      }
      return result;
    }

    /**
     * initialize
     */
    public void init(TripleQuery query) {
    }
  } // TopicBase
 /**
  * Family
  * In most societies, the family is the principal institution for the socialization of children.
  */
  public static class Family extends TopicBase {
  
    public String name;
    public String weddingDate;
    public String weddingPlace;
    public String yearMarried;
    public String monthMarried;
    public String divorced;
    public String husbandOf;
    public String wifeOf;

    public String getName() { return name; }
    public void setName(String pName) { name=pName; }
    public String getWeddingDate() { return weddingDate; }
    public void setWeddingDate(String pWeddingDate) { weddingDate=pWeddingDate; }
    public String getWeddingPlace() { return weddingPlace; }
    public void setWeddingPlace(String pWeddingPlace) { weddingPlace=pWeddingPlace; }
    public String getYearMarried() { return yearMarried; }
    public void setYearMarried(String pYearMarried) { yearMarried=pYearMarried; }
    public String getMonthMarried() { return monthMarried; }
    public void setMonthMarried(String pMonthMarried) { monthMarried=pMonthMarried; }
    public String getDivorced() { return divorced; }
    public void setDivorced(String pDivorced) { divorced=pDivorced; }
    public String getHusbandOf() { return husbandOf; }
    public void setHusbandOf(String pHusbandOf) { husbandOf=pHusbandOf; }
    public String getWifeOf() { return wifeOf; }
    public void setWifeOf(String pWifeOf) { wifeOf=pWifeOf; }
    /**
     * convert this Family to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this Family to a WikiSon string
     * @return the WikiSon representation of this Family
     */
    public String toWikiSon() {
      String wikison= "{{Family\n";
      wikison+=toWikiSon("name",name);
      wikison+=toWikiSon("weddingDate",weddingDate);
      wikison+=toWikiSon("weddingPlace",weddingPlace);
      wikison+=toWikiSon("yearMarried",yearMarried);
      wikison+=toWikiSon("monthMarried",monthMarried);
      wikison+=toWikiSon("divorced",divorced);
      wikison+=toWikiSon("husbandOf",husbandOf);
      wikison+=toWikiSon("wifeOf",wifeOf);
      wikison+="}}\n";
      return wikison;
    }

/**
     * convert this Family to a SiDIF string
     * @return the SiDIF representation of this Family
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA Family\n",this.pageid);
      siDIF+=propertySiDIF("name",name,Text);
      siDIF+=propertySiDIF("weddingDate",weddingDate,Date);
      siDIF+=propertySiDIF("weddingPlace",weddingPlace,Text);
      siDIF+=propertySiDIF("yearMarried",yearMarried,Number);
      siDIF+=propertySiDIF("monthMarried",monthMarried,Number);
      siDIF+=propertySiDIF("divorced",divorced,Date);
      siDIF+=propertySiDIF("husbandOf",husbandOf,Page);
      siDIF+=propertySiDIF("wifeOf",wifeOf,Page);
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

    /**
     * default constructor for Family
     */
    public Family() {}

    /**
     * construct a Family from the given Triple
     * @param query - the TripleQuery to get the triples from
     * @param pFamilyTriple - the triple to construct me from
     */
    public Family(TripleQuery query,Triple pFamilyTriple) {
      this(query,pFamilyTriple.getSubject().toString());
    } // constructor

    /**
     * construct a Family from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public Family(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple nameTriple=query.selectSingle(pageid,"name",null);
      if (nameTriple==null)
        nameTriple=query.selectSingle(pageid,"Property:Family_name",null);
      if (nameTriple!=null) 
        name=nameTriple.getObject().toString();
      Triple weddingDateTriple=query.selectSingle(pageid,"weddingDate",null);
      if (weddingDateTriple==null)
        weddingDateTriple=query.selectSingle(pageid,"Property:Family_weddingDate",null);
      if (weddingDateTriple!=null) 
        weddingDate=weddingDateTriple.getObject().toString();
      Triple weddingPlaceTriple=query.selectSingle(pageid,"weddingPlace",null);
      if (weddingPlaceTriple==null)
        weddingPlaceTriple=query.selectSingle(pageid,"Property:Family_weddingPlace",null);
      if (weddingPlaceTriple!=null) 
        weddingPlace=weddingPlaceTriple.getObject().toString();
      Triple yearMarriedTriple=query.selectSingle(pageid,"yearMarried",null);
      if (yearMarriedTriple==null)
        yearMarriedTriple=query.selectSingle(pageid,"Property:Family_yearMarried",null);
      if (yearMarriedTriple!=null) 
        yearMarried=yearMarriedTriple.getObject().toString();
      Triple monthMarriedTriple=query.selectSingle(pageid,"monthMarried",null);
      if (monthMarriedTriple==null)
        monthMarriedTriple=query.selectSingle(pageid,"Property:Family_monthMarried",null);
      if (monthMarriedTriple!=null) 
        monthMarried=monthMarriedTriple.getObject().toString();
      Triple divorcedTriple=query.selectSingle(pageid,"divorced",null);
      if (divorcedTriple==null)
        divorcedTriple=query.selectSingle(pageid,"Property:Family_divorced",null);
      if (divorcedTriple!=null) 
        divorced=divorcedTriple.getObject().toString();
      Triple husbandOfTriple=query.selectSingle(pageid,"husbandOf",null);
      if (husbandOfTriple==null)
        husbandOfTriple=query.selectSingle(pageid,"Property:Family_husbandOf",null);
      if (husbandOfTriple!=null) 
        husbandOf=husbandOfTriple.getObject().toString();
      Triple wifeOfTriple=query.selectSingle(pageid,"wifeOf",null);
      if (wifeOfTriple==null)
        wifeOfTriple=query.selectSingle(pageid,"Property:Family_wifeOf",null);
      if (wifeOfTriple!=null) 
        wifeOf=wifeOfTriple.getObject().toString();
      init(query);
    } // constructor for Family
    
    // >>>{user defined topic code}{Family}{Family}
    // <<<{user defined topic code}{Family}{Family}
  } // class Family
  /**
   * Manager for Family
   */
  public static class FamilyManager extends TopicBase {
 
    public String topicName="Family";
    public transient List<Family> mFamilys=new ArrayList<Family>();
    public transient Map<String,Family> mFamilyMap=new LinkedHashMap<String,Family>();

    /**
     * get my Families
     */
    public List<Family> getFamilies() {
      List<Family> result=this.mFamilys;
      return result;
    }

    /**
     *  add a new Family 
     */
    public Family add(Family pFamily) {
      mFamilys.add(pFamily);
      mFamilyMap.put(pFamily.getPageid(),pFamily);
      return pFamily;
    }

    /**
     *  add a new Family from the given triple
     */
    public Family add(TripleQuery query,Triple pFamilyTriple) {
      Family lFamily=new Family(query,pFamilyTriple);
      add(lFamily);
      return lFamily;
    }

    // reinitialize my mFamily map
    public void reinit() {
      mFamilyMap.clear();
      for (Family lFamily:mFamilys) {
        mFamilyMap.put(lFamily.getPageid(),lFamily);
      }
    }

    // convert this manager to json format 
    public String toJson() { return JSON.toJSONString(this); }
    
    // get a new manager from the given json string
    public static FamilyManager fromJson(String json) {
      FamilyManager result=JSON.parseObject(json, FamilyManager.class);
      result.reinit();
      return result;
    }

    // default constructor for Family Manager
    public FamilyManager() {}

    // add Families from the given query
    public void addFamilies(TripleQuery pFamilyQuery,TripleQuery query) {
      if (pFamilyQuery!=null) {
        for (Triple lFamilyTriple:pFamilyQuery.getTriples()) {
          add(query,lFamilyTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public FamilyManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lFamilyQuery=query.query(null,"isA","Family");
      addFamilies(lFamilyQuery,query);
      // then the SMW triplestore
      lFamilyQuery=query.query(null,"Property:IsA","Family");
      addFamilies(lFamilyQuery,query);
      init(query);
    } // constructor for Family Manager
    
    // >>>{user defined topicmanager code}{Family}{Family}
    // <<<{user defined topicmanager code}{Family}{Family}
  } // class Family Manager
 /**
  * Person
  * A Person is a human being
  */
  public static class Person extends TopicBase {
  
    public String qid;
    public String royal92id;
    public String name;
    public String nobleTitle;
    public String picture;
    public String sex;
    public String born;
    public String yearBorn;
    public String monthBorn;
    public String birthPlace;
    public String died;
    public String diedAt;
    public String yearDied;
    public String monthDied;
    public String noInLine;
    public String wikiPedia;
    public String childOf;
    public String parentOf;
    public String spouse;

    public String getQid() { return qid; }
    public void setQid(String pQid) { qid=pQid; }
    public String getRoyal92id() { return royal92id; }
    public void setRoyal92id(String pRoyal92id) { royal92id=pRoyal92id; }
    public String getName() { return name; }
    public void setName(String pName) { name=pName; }
    public String getNobleTitle() { return nobleTitle; }
    public void setNobleTitle(String pNobleTitle) { nobleTitle=pNobleTitle; }
    public String getPicture() { return picture; }
    public void setPicture(String pPicture) { picture=pPicture; }
    public String getSex() { return sex; }
    public void setSex(String pSex) { sex=pSex; }
    public String getBorn() { return born; }
    public void setBorn(String pBorn) { born=pBorn; }
    public String getYearBorn() { return yearBorn; }
    public void setYearBorn(String pYearBorn) { yearBorn=pYearBorn; }
    public String getMonthBorn() { return monthBorn; }
    public void setMonthBorn(String pMonthBorn) { monthBorn=pMonthBorn; }
    public String getBirthPlace() { return birthPlace; }
    public void setBirthPlace(String pBirthPlace) { birthPlace=pBirthPlace; }
    public String getDied() { return died; }
    public void setDied(String pDied) { died=pDied; }
    public String getDiedAt() { return diedAt; }
    public void setDiedAt(String pDiedAt) { diedAt=pDiedAt; }
    public String getYearDied() { return yearDied; }
    public void setYearDied(String pYearDied) { yearDied=pYearDied; }
    public String getMonthDied() { return monthDied; }
    public void setMonthDied(String pMonthDied) { monthDied=pMonthDied; }
    public String getNoInLine() { return noInLine; }
    public void setNoInLine(String pNoInLine) { noInLine=pNoInLine; }
    public String getWikiPedia() { return wikiPedia; }
    public void setWikiPedia(String pWikiPedia) { wikiPedia=pWikiPedia; }
    public String getChildOf() { return childOf; }
    public void setChildOf(String pChildOf) { childOf=pChildOf; }
    public String getParentOf() { return parentOf; }
    public void setParentOf(String pParentOf) { parentOf=pParentOf; }
    public String getSpouse() { return spouse; }
    public void setSpouse(String pSpouse) { spouse=pSpouse; }
    /**
     * convert this Person to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this Person to a WikiSon string
     * @return the WikiSon representation of this Person
     */
    public String toWikiSon() {
      String wikison= "{{Person\n";
      wikison+=toWikiSon("qid",qid);
      wikison+=toWikiSon("royal92id",royal92id);
      wikison+=toWikiSon("name",name);
      wikison+=toWikiSon("nobleTitle",nobleTitle);
      wikison+=toWikiSon("picture",picture);
      wikison+=toWikiSon("sex",sex);
      wikison+=toWikiSon("born",born);
      wikison+=toWikiSon("yearBorn",yearBorn);
      wikison+=toWikiSon("monthBorn",monthBorn);
      wikison+=toWikiSon("birthPlace",birthPlace);
      wikison+=toWikiSon("died",died);
      wikison+=toWikiSon("diedAt",diedAt);
      wikison+=toWikiSon("yearDied",yearDied);
      wikison+=toWikiSon("monthDied",monthDied);
      wikison+=toWikiSon("noInLine",noInLine);
      wikison+=toWikiSon("wikiPedia",wikiPedia);
      wikison+=toWikiSon("childOf",childOf);
      wikison+=toWikiSon("parentOf",parentOf);
      wikison+=toWikiSon("spouse",spouse);
      wikison+="}}\n";
      return wikison;
    }

/**
     * convert this Person to a SiDIF string
     * @return the SiDIF representation of this Person
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA Person\n",this.pageid);
      siDIF+=propertySiDIF("qid",qid,Text);
      siDIF+=propertySiDIF("royal92id",royal92id,Text);
      siDIF+=propertySiDIF("name",name,Text);
      siDIF+=propertySiDIF("nobleTitle",nobleTitle,Text);
      siDIF+=propertySiDIF("picture",picture,URL);
      siDIF+=propertySiDIF("sex",sex,Text);
      siDIF+=propertySiDIF("born",born,Date);
      siDIF+=propertySiDIF("yearBorn",yearBorn,Number);
      siDIF+=propertySiDIF("monthBorn",monthBorn,Number);
      siDIF+=propertySiDIF("birthPlace",birthPlace,Text);
      siDIF+=propertySiDIF("died",died,Date);
      siDIF+=propertySiDIF("diedAt",diedAt,Text);
      siDIF+=propertySiDIF("yearDied",yearDied,Number);
      siDIF+=propertySiDIF("monthDied",monthDied,Number);
      siDIF+=propertySiDIF("noInLine",noInLine,Number);
      siDIF+=propertySiDIF("wikiPedia",wikiPedia,URL);
      siDIF+=propertySiDIF("childOf",childOf,Page);
      siDIF+=propertySiDIF("parentOf",parentOf,Page);
      siDIF+=propertySiDIF("spouse",spouse,Page);
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

    /**
     * default constructor for Person
     */
    public Person() {}

    /**
     * construct a Person from the given Triple
     * @param query - the TripleQuery to get the triples from
     * @param pPersonTriple - the triple to construct me from
     */
    public Person(TripleQuery query,Triple pPersonTriple) {
      this(query,pPersonTriple.getSubject().toString());
    } // constructor

    /**
     * construct a Person from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public Person(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple qidTriple=query.selectSingle(pageid,"qid",null);
      if (qidTriple==null)
        qidTriple=query.selectSingle(pageid,"Property:Person_qid",null);
      if (qidTriple!=null) 
        qid=qidTriple.getObject().toString();
      Triple royal92idTriple=query.selectSingle(pageid,"royal92id",null);
      if (royal92idTriple==null)
        royal92idTriple=query.selectSingle(pageid,"Property:Person_royal92id",null);
      if (royal92idTriple!=null) 
        royal92id=royal92idTriple.getObject().toString();
      Triple nameTriple=query.selectSingle(pageid,"name",null);
      if (nameTriple==null)
        nameTriple=query.selectSingle(pageid,"Property:Person_name",null);
      if (nameTriple!=null) 
        name=nameTriple.getObject().toString();
      Triple nobleTitleTriple=query.selectSingle(pageid,"nobleTitle",null);
      if (nobleTitleTriple==null)
        nobleTitleTriple=query.selectSingle(pageid,"Property:Person_nobleTitle",null);
      if (nobleTitleTriple!=null) 
        nobleTitle=nobleTitleTriple.getObject().toString();
      Triple pictureTriple=query.selectSingle(pageid,"picture",null);
      if (pictureTriple==null)
        pictureTriple=query.selectSingle(pageid,"Property:Person_picture",null);
      if (pictureTriple!=null) 
        picture=pictureTriple.getObject().toString();
      Triple sexTriple=query.selectSingle(pageid,"sex",null);
      if (sexTriple==null)
        sexTriple=query.selectSingle(pageid,"Property:Person_sex",null);
      if (sexTriple!=null) 
        sex=sexTriple.getObject().toString();
      Triple bornTriple=query.selectSingle(pageid,"born",null);
      if (bornTriple==null)
        bornTriple=query.selectSingle(pageid,"Property:Person_born",null);
      if (bornTriple!=null) 
        born=bornTriple.getObject().toString();
      Triple yearBornTriple=query.selectSingle(pageid,"yearBorn",null);
      if (yearBornTriple==null)
        yearBornTriple=query.selectSingle(pageid,"Property:Person_yearBorn",null);
      if (yearBornTriple!=null) 
        yearBorn=yearBornTriple.getObject().toString();
      Triple monthBornTriple=query.selectSingle(pageid,"monthBorn",null);
      if (monthBornTriple==null)
        monthBornTriple=query.selectSingle(pageid,"Property:Person_monthBorn",null);
      if (monthBornTriple!=null) 
        monthBorn=monthBornTriple.getObject().toString();
      Triple birthPlaceTriple=query.selectSingle(pageid,"birthPlace",null);
      if (birthPlaceTriple==null)
        birthPlaceTriple=query.selectSingle(pageid,"Property:Person_birthPlace",null);
      if (birthPlaceTriple!=null) 
        birthPlace=birthPlaceTriple.getObject().toString();
      Triple diedTriple=query.selectSingle(pageid,"died",null);
      if (diedTriple==null)
        diedTriple=query.selectSingle(pageid,"Property:Person_died",null);
      if (diedTriple!=null) 
        died=diedTriple.getObject().toString();
      Triple diedAtTriple=query.selectSingle(pageid,"diedAt",null);
      if (diedAtTriple==null)
        diedAtTriple=query.selectSingle(pageid,"Property:Person_diedAt",null);
      if (diedAtTriple!=null) 
        diedAt=diedAtTriple.getObject().toString();
      Triple yearDiedTriple=query.selectSingle(pageid,"yearDied",null);
      if (yearDiedTriple==null)
        yearDiedTriple=query.selectSingle(pageid,"Property:Person_yearDied",null);
      if (yearDiedTriple!=null) 
        yearDied=yearDiedTriple.getObject().toString();
      Triple monthDiedTriple=query.selectSingle(pageid,"monthDied",null);
      if (monthDiedTriple==null)
        monthDiedTriple=query.selectSingle(pageid,"Property:Person_monthDied",null);
      if (monthDiedTriple!=null) 
        monthDied=monthDiedTriple.getObject().toString();
      Triple noInLineTriple=query.selectSingle(pageid,"noInLine",null);
      if (noInLineTriple==null)
        noInLineTriple=query.selectSingle(pageid,"Property:Person_noInLine",null);
      if (noInLineTriple!=null) 
        noInLine=noInLineTriple.getObject().toString();
      Triple wikiPediaTriple=query.selectSingle(pageid,"wikiPedia",null);
      if (wikiPediaTriple==null)
        wikiPediaTriple=query.selectSingle(pageid,"Property:Person_wikiPedia",null);
      if (wikiPediaTriple!=null) 
        wikiPedia=wikiPediaTriple.getObject().toString();
      Triple childOfTriple=query.selectSingle(pageid,"childOf",null);
      if (childOfTriple==null)
        childOfTriple=query.selectSingle(pageid,"Property:Person_childOf",null);
      if (childOfTriple!=null) 
        childOf=childOfTriple.getObject().toString();
      Triple parentOfTriple=query.selectSingle(pageid,"parentOf",null);
      if (parentOfTriple==null)
        parentOfTriple=query.selectSingle(pageid,"Property:Person_parentOf",null);
      if (parentOfTriple!=null) 
        parentOf=parentOfTriple.getObject().toString();
      Triple spouseTriple=query.selectSingle(pageid,"spouse",null);
      if (spouseTriple==null)
        spouseTriple=query.selectSingle(pageid,"Property:Person_spouse",null);
      if (spouseTriple!=null) 
        spouse=spouseTriple.getObject().toString();
      init(query);
    } // constructor for Person
    
    // >>>{user defined topic code}{Person}{Person}
    // <<<{user defined topic code}{Person}{Person}
  } // class Person
  /**
   * Manager for Person
   */
  public static class PersonManager extends TopicBase {
 
    public String topicName="Person";
    public transient List<Person> mPersons=new ArrayList<Person>();
    public transient Map<String,Person> mPersonMap=new LinkedHashMap<String,Person>();

    /**
     * get my Persons
     */
    public List<Person> getPersons() {
      List<Person> result=this.mPersons;
      return result;
    }

    /**
     *  add a new Person 
     */
    public Person add(Person pPerson) {
      mPersons.add(pPerson);
      mPersonMap.put(pPerson.getPageid(),pPerson);
      return pPerson;
    }

    /**
     *  add a new Person from the given triple
     */
    public Person add(TripleQuery query,Triple pPersonTriple) {
      Person lPerson=new Person(query,pPersonTriple);
      add(lPerson);
      return lPerson;
    }

    // reinitialize my mPerson map
    public void reinit() {
      mPersonMap.clear();
      for (Person lPerson:mPersons) {
        mPersonMap.put(lPerson.getPageid(),lPerson);
      }
    }

    // convert this manager to json format 
    public String toJson() { return JSON.toJSONString(this); }
    
    // get a new manager from the given json string
    public static PersonManager fromJson(String json) {
      PersonManager result=JSON.parseObject(json, PersonManager.class);
      result.reinit();
      return result;
    }

    // default constructor for Person Manager
    public PersonManager() {}

    // add Persons from the given query
    public void addPersons(TripleQuery pPersonQuery,TripleQuery query) {
      if (pPersonQuery!=null) {
        for (Triple lPersonTriple:pPersonQuery.getTriples()) {
          add(query,lPersonTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public PersonManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lPersonQuery=query.query(null,"isA","Person");
      addPersons(lPersonQuery,query);
      // then the SMW triplestore
      lPersonQuery=query.query(null,"Property:IsA","Person");
      addPersons(lPersonQuery,query);
      init(query);
    } // constructor for Person Manager
    
    // >>>{user defined topicmanager code}{Person}{Person}
    // <<<{user defined topicmanager code}{Person}{Person}
  } // class Person Manager

}
Showing below 0 pages.

Retrieved from "http://royal-family.bitplan.com/index.php?title=Concept:Person/Java&oldid=1303#smw-result"