Difference between revisions of "Concept:Event/Java"
Jump to navigation
Jump to search
(created by WikiTask 2020-07-22T12:23:02Z) |
m (created by WikiTask 2020-10-06T06:34:45Z) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 98: | Line 98: | ||
} | } | ||
} // TopicBase | } // TopicBase | ||
+ | /** | ||
+ | * EventSeries | ||
+ | * a series of Events | ||
+ | */ | ||
+ | public static class EventSeries extends TopicBase { | ||
+ | |||
+ | public String acronym; | ||
+ | public String homepage; | ||
+ | |||
+ | public String getAcronym() { return acronym; } | ||
+ | public void setAcronym(String pAcronym) { acronym=pAcronym; } | ||
+ | public String getHomepage() { return homepage; } | ||
+ | public void setHomepage(String pHomepage) { homepage=pHomepage; } | ||
+ | /** | ||
+ | * convert this EventSeries to a JSON string | ||
+ | * @return the JSON representation | ||
+ | */ | ||
+ | public String toJson() { return JSON.toJSONString(this); } | ||
+ | |||
+ | /** | ||
+ | * convert this EventSeries to a WikiSon string | ||
+ | * @return the WikiSon representation of this EventSeries | ||
+ | */ | ||
+ | public String toWikiSon() { | ||
+ | String wikison= "{{EventSeries\n"; | ||
+ | wikison+=toWikiSon("acronym",acronym); | ||
+ | wikison+=toWikiSon("homepage",homepage); | ||
+ | wikison+="}}\n"; | ||
+ | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this EventSeries to a SiDIF string | ||
+ | * @return the SiDIF representation of this EventSeries | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA EventSeries\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("acronym",acronym,"text"); | ||
+ | siDIF+=propertySiDIF("homepage",homepage,"url"); | ||
+ | return siDIF; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * get the pageid for this topic | ||
+ | */ | ||
+ | public String getPageid() { return pageid; }; | ||
+ | |||
+ | /** | ||
+ | * default constructor for EventSeries | ||
+ | */ | ||
+ | public EventSeries() {} | ||
+ | |||
+ | /** | ||
+ | * construct a EventSeries from the given Triple | ||
+ | * @param query - the TripleQuery to get the triples from | ||
+ | * @param pEventSeriesTriple - the triple to construct me from | ||
+ | */ | ||
+ | public EventSeries(TripleQuery query,Triple pEventSeriesTriple) { | ||
+ | this(query,pEventSeriesTriple.getSubject().toString()); | ||
+ | } // constructor | ||
+ | |||
+ | /** | ||
+ | * construct a EventSeries from the given pageId | ||
+ | * @param query - the TripleQuery to get the triples from | ||
+ | * @param pageid - pageid | ||
+ | */ | ||
+ | public EventSeries(TripleQuery query,String pageid) { | ||
+ | this.pageid=pageid; | ||
+ | Triple acronymTriple=query.selectSingle(pageid,"acronym",null); | ||
+ | if (acronymTriple==null) | ||
+ | acronymTriple=query.selectSingle(pageid,"Property:EventSeries_acronym",null); | ||
+ | if (acronymTriple!=null) | ||
+ | acronym=acronymTriple.getObject().toString(); | ||
+ | Triple homepageTriple=query.selectSingle(pageid,"homepage",null); | ||
+ | if (homepageTriple==null) | ||
+ | homepageTriple=query.selectSingle(pageid,"Property:EventSeries_homepage",null); | ||
+ | if (homepageTriple!=null) | ||
+ | homepage=homepageTriple.getObject().toString(); | ||
+ | init(query); | ||
+ | } // constructor for EventSeries | ||
+ | |||
+ | // >>>{user defined topic code}{EventSeries}{EventSeries} | ||
+ | // <<<{user defined topic code}{EventSeries}{EventSeries} | ||
+ | } // class EventSeries | ||
+ | /** | ||
+ | * Manager for EventSeries | ||
+ | */ | ||
+ | public static class EventSeriesManager extends TopicBase { | ||
+ | |||
+ | public String topicName="EventSeries"; | ||
+ | public transient List<EventSeries> mEventSeriess=new ArrayList<EventSeries>(); | ||
+ | public transient Map<String,EventSeries> mEventSeriesMap=new LinkedHashMap<String,EventSeries>(); | ||
+ | |||
+ | /** | ||
+ | * get my EventSeries | ||
+ | */ | ||
+ | public List<EventSeries> getEventSeries() { | ||
+ | List<EventSeries> result=this.mEventSeriess; | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add a new EventSeries | ||
+ | */ | ||
+ | public EventSeries add(EventSeries pEventSeries) { | ||
+ | mEventSeriess.add(pEventSeries); | ||
+ | mEventSeriesMap.put(pEventSeries.getPageid(),pEventSeries); | ||
+ | return pEventSeries; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add a new EventSeries from the given triple | ||
+ | */ | ||
+ | public EventSeries add(TripleQuery query,Triple pEventSeriesTriple) { | ||
+ | EventSeries lEventSeries=new EventSeries(query,pEventSeriesTriple); | ||
+ | add(lEventSeries); | ||
+ | return lEventSeries; | ||
+ | } | ||
+ | |||
+ | // reinitialize my mEventSeries map | ||
+ | public void reinit() { | ||
+ | mEventSeriesMap.clear(); | ||
+ | for (EventSeries lEventSeries:mEventSeriess) { | ||
+ | mEventSeriesMap.put(lEventSeries.getPageid(),lEventSeries); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // convert this manager to json format | ||
+ | public String toJson() { return JSON.toJSONString(this); } | ||
+ | |||
+ | // get a new manager from the given json string | ||
+ | public static EventSeriesManager fromJson(String json) { | ||
+ | EventSeriesManager result=JSON.parseObject(json, EventSeriesManager.class); | ||
+ | result.reinit(); | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | // default constructor for EventSeries Manager | ||
+ | public EventSeriesManager() {} | ||
+ | |||
+ | // add EventSeries from the given query | ||
+ | public void addEventSeries(TripleQuery pEventSeriesQuery,TripleQuery query) { | ||
+ | if (pEventSeriesQuery!=null) { | ||
+ | for (Triple lEventSeriesTriple:pEventSeriesQuery.getTriples()) { | ||
+ | add(query,lEventSeriesTriple); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // construct me from the given triple Query query | ||
+ | public EventSeriesManager(TripleQuery query) { | ||
+ | // first query the SiDIF bases triplestore | ||
+ | TripleQuery lEventSeriesQuery=query.query(null,"isA","EventSeries"); | ||
+ | addEventSeries(lEventSeriesQuery,query); | ||
+ | // then the SMW triplestore | ||
+ | lEventSeriesQuery=query.query(null,"Property:IsA","EventSeries"); | ||
+ | addEventSeries(lEventSeriesQuery,query); | ||
+ | init(query); | ||
+ | } // constructor for EventSeries Manager | ||
+ | |||
+ | // >>>{user defined topicmanager code}{EventSeries}{EventSeries} | ||
+ | // <<<{user defined topicmanager code}{EventSeries}{EventSeries} | ||
+ | } // class EventSeries Manager | ||
/** | /** | ||
* Event | * Event | ||
Line 105: | Line 268: | ||
public String acronym; | public String acronym; | ||
+ | public String homepage; | ||
+ | public String wikidataid; | ||
+ | public String series; | ||
+ | public String city; | ||
+ | public String region; | ||
+ | public String country; | ||
public String getAcronym() { return acronym; } | public String getAcronym() { return acronym; } | ||
public void setAcronym(String pAcronym) { acronym=pAcronym; } | public void setAcronym(String pAcronym) { acronym=pAcronym; } | ||
+ | public String getHomepage() { return homepage; } | ||
+ | public void setHomepage(String pHomepage) { homepage=pHomepage; } | ||
+ | public String getWikidataid() { return wikidataid; } | ||
+ | public void setWikidataid(String pWikidataid) { wikidataid=pWikidataid; } | ||
+ | public String getSeries() { return series; } | ||
+ | public void setSeries(String pSeries) { series=pSeries; } | ||
+ | public String getCity() { return city; } | ||
+ | public void setCity(String pCity) { city=pCity; } | ||
+ | public String getRegion() { return region; } | ||
+ | public void setRegion(String pRegion) { region=pRegion; } | ||
+ | public String getCountry() { return country; } | ||
+ | public void setCountry(String pCountry) { country=pCountry; } | ||
/** | /** | ||
* convert this Event to a JSON string | * convert this Event to a JSON string | ||
Line 121: | Line 302: | ||
String wikison= "{{Event\n"; | String wikison= "{{Event\n"; | ||
wikison+=toWikiSon("acronym",acronym); | wikison+=toWikiSon("acronym",acronym); | ||
+ | wikison+=toWikiSon("homepage",homepage); | ||
+ | wikison+=toWikiSon("wikidataid",wikidataid); | ||
+ | wikison+=toWikiSon("series",series); | ||
+ | wikison+=toWikiSon("city",city); | ||
+ | wikison+=toWikiSon("region",region); | ||
+ | wikison+=toWikiSon("country",country); | ||
wikison+="}}\n"; | wikison+="}}\n"; | ||
return wikison; | return wikison; | ||
Line 131: | Line 318: | ||
public String toSiDIF() { | public String toSiDIF() { | ||
String siDIF = String.format("%s isA Event\n",this.pageid); | String siDIF = String.format("%s isA Event\n",this.pageid); | ||
− | siDIF+=propertySiDIF("acronym",acronym," | + | siDIF+=propertySiDIF("acronym",acronym,"text"); |
+ | siDIF+=propertySiDIF("homepage",homepage,"url"); | ||
+ | siDIF+=propertySiDIF("wikidataid",wikidataid,"text"); | ||
+ | siDIF+=propertySiDIF("series",series,"Page"); | ||
+ | siDIF+=propertySiDIF("city",city,"Page"); | ||
+ | siDIF+=propertySiDIF("region",region,"Page"); | ||
+ | siDIF+=propertySiDIF("country",country,"Page"); | ||
return siDIF; | return siDIF; | ||
} | } | ||
Line 166: | Line 359: | ||
if (acronymTriple!=null) | if (acronymTriple!=null) | ||
acronym=acronymTriple.getObject().toString(); | acronym=acronymTriple.getObject().toString(); | ||
+ | Triple homepageTriple=query.selectSingle(pageid,"homepage",null); | ||
+ | if (homepageTriple==null) | ||
+ | homepageTriple=query.selectSingle(pageid,"Property:Event_homepage",null); | ||
+ | if (homepageTriple!=null) | ||
+ | homepage=homepageTriple.getObject().toString(); | ||
+ | Triple wikidataidTriple=query.selectSingle(pageid,"wikidataid",null); | ||
+ | if (wikidataidTriple==null) | ||
+ | wikidataidTriple=query.selectSingle(pageid,"Property:Event_wikidataid",null); | ||
+ | if (wikidataidTriple!=null) | ||
+ | wikidataid=wikidataidTriple.getObject().toString(); | ||
+ | Triple seriesTriple=query.selectSingle(pageid,"series",null); | ||
+ | if (seriesTriple==null) | ||
+ | seriesTriple=query.selectSingle(pageid,"Property:Event_series",null); | ||
+ | if (seriesTriple!=null) | ||
+ | series=seriesTriple.getObject().toString(); | ||
+ | Triple cityTriple=query.selectSingle(pageid,"city",null); | ||
+ | if (cityTriple==null) | ||
+ | cityTriple=query.selectSingle(pageid,"Property:Event_city",null); | ||
+ | if (cityTriple!=null) | ||
+ | city=cityTriple.getObject().toString(); | ||
+ | Triple regionTriple=query.selectSingle(pageid,"region",null); | ||
+ | if (regionTriple==null) | ||
+ | regionTriple=query.selectSingle(pageid,"Property:Event_region",null); | ||
+ | if (regionTriple!=null) | ||
+ | region=regionTriple.getObject().toString(); | ||
+ | Triple countryTriple=query.selectSingle(pageid,"country",null); | ||
+ | if (countryTriple==null) | ||
+ | countryTriple=query.selectSingle(pageid,"Property:Event_country",null); | ||
+ | if (countryTriple!=null) | ||
+ | country=countryTriple.getObject().toString(); | ||
init(query); | init(query); | ||
} // constructor for Event | } // constructor for Event | ||
Line 251: | Line 474: | ||
// <<<{user defined topicmanager code}{Event}{Event} | // <<<{user defined topicmanager code}{Event}{Event} | ||
} // class Event Manager | } // class Event Manager | ||
+ | /** | ||
+ | * City | ||
+ | * large permanent human settlement | ||
+ | */ | ||
+ | public static class City extends TopicBase { | ||
+ | |||
+ | public String name; | ||
+ | public String wikidataid; | ||
+ | |||
+ | public String getName() { return name; } | ||
+ | public void setName(String pName) { name=pName; } | ||
+ | public String getWikidataid() { return wikidataid; } | ||
+ | public void setWikidataid(String pWikidataid) { wikidataid=pWikidataid; } | ||
+ | /** | ||
+ | * convert this City to a JSON string | ||
+ | * @return the JSON representation | ||
+ | */ | ||
+ | public String toJson() { return JSON.toJSONString(this); } | ||
+ | |||
+ | /** | ||
+ | * convert this City to a WikiSon string | ||
+ | * @return the WikiSon representation of this City | ||
+ | */ | ||
+ | public String toWikiSon() { | ||
+ | String wikison= "{{City\n"; | ||
+ | wikison+=toWikiSon("name",name); | ||
+ | wikison+=toWikiSon("wikidataid",wikidataid); | ||
+ | wikison+="}}\n"; | ||
+ | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this City to a SiDIF string | ||
+ | * @return the SiDIF representation of this City | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA City\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("name",name,"text"); | ||
+ | siDIF+=propertySiDIF("wikidataid",wikidataid,"text"); | ||
+ | return siDIF; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * get the pageid for this topic | ||
+ | */ | ||
+ | public String getPageid() { return pageid; }; | ||
+ | |||
+ | /** | ||
+ | * default constructor for City | ||
+ | */ | ||
+ | public City() {} | ||
+ | |||
+ | /** | ||
+ | * construct a City from the given Triple | ||
+ | * @param query - the TripleQuery to get the triples from | ||
+ | * @param pCityTriple - the triple to construct me from | ||
+ | */ | ||
+ | public City(TripleQuery query,Triple pCityTriple) { | ||
+ | this(query,pCityTriple.getSubject().toString()); | ||
+ | } // constructor | ||
+ | |||
+ | /** | ||
+ | * construct a City from the given pageId | ||
+ | * @param query - the TripleQuery to get the triples from | ||
+ | * @param pageid - pageid | ||
+ | */ | ||
+ | public City(TripleQuery query,String pageid) { | ||
+ | this.pageid=pageid; | ||
+ | Triple nameTriple=query.selectSingle(pageid,"name",null); | ||
+ | if (nameTriple==null) | ||
+ | nameTriple=query.selectSingle(pageid,"Property:City_name",null); | ||
+ | if (nameTriple!=null) | ||
+ | name=nameTriple.getObject().toString(); | ||
+ | Triple wikidataidTriple=query.selectSingle(pageid,"wikidataid",null); | ||
+ | if (wikidataidTriple==null) | ||
+ | wikidataidTriple=query.selectSingle(pageid,"Property:City_wikidataid",null); | ||
+ | if (wikidataidTriple!=null) | ||
+ | wikidataid=wikidataidTriple.getObject().toString(); | ||
+ | init(query); | ||
+ | } // constructor for City | ||
+ | |||
+ | // >>>{user defined topic code}{City}{City} | ||
+ | // <<<{user defined topic code}{City}{City} | ||
+ | } // class City | ||
+ | /** | ||
+ | * Manager for City | ||
+ | */ | ||
+ | public static class CityManager extends TopicBase { | ||
+ | |||
+ | public String topicName="City"; | ||
+ | public transient List<City> mCitys=new ArrayList<City>(); | ||
+ | public transient Map<String,City> mCityMap=new LinkedHashMap<String,City>(); | ||
+ | |||
+ | /** | ||
+ | * get my Cities | ||
+ | */ | ||
+ | public List<City> getCities() { | ||
+ | List<City> result=this.mCitys; | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add a new City | ||
+ | */ | ||
+ | public City add(City pCity) { | ||
+ | mCitys.add(pCity); | ||
+ | mCityMap.put(pCity.getPageid(),pCity); | ||
+ | return pCity; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add a new City from the given triple | ||
+ | */ | ||
+ | public City add(TripleQuery query,Triple pCityTriple) { | ||
+ | City lCity=new City(query,pCityTriple); | ||
+ | add(lCity); | ||
+ | return lCity; | ||
+ | } | ||
+ | |||
+ | // reinitialize my mCity map | ||
+ | public void reinit() { | ||
+ | mCityMap.clear(); | ||
+ | for (City lCity:mCitys) { | ||
+ | mCityMap.put(lCity.getPageid(),lCity); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // convert this manager to json format | ||
+ | public String toJson() { return JSON.toJSONString(this); } | ||
+ | |||
+ | // get a new manager from the given json string | ||
+ | public static CityManager fromJson(String json) { | ||
+ | CityManager result=JSON.parseObject(json, CityManager.class); | ||
+ | result.reinit(); | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | // default constructor for City Manager | ||
+ | public CityManager() {} | ||
+ | |||
+ | // add Cities from the given query | ||
+ | public void addCities(TripleQuery pCityQuery,TripleQuery query) { | ||
+ | if (pCityQuery!=null) { | ||
+ | for (Triple lCityTriple:pCityQuery.getTriples()) { | ||
+ | add(query,lCityTriple); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // construct me from the given triple Query query | ||
+ | public CityManager(TripleQuery query) { | ||
+ | // first query the SiDIF bases triplestore | ||
+ | TripleQuery lCityQuery=query.query(null,"isA","City"); | ||
+ | addCities(lCityQuery,query); | ||
+ | // then the SMW triplestore | ||
+ | lCityQuery=query.query(null,"Property:IsA","City"); | ||
+ | addCities(lCityQuery,query); | ||
+ | init(query); | ||
+ | } // constructor for City Manager | ||
+ | |||
+ | // >>>{user defined topicmanager code}{City}{City} | ||
+ | // <<<{user defined topicmanager code}{City}{City} | ||
+ | } // class City Manager | ||
+ | /** | ||
+ | * Country | ||
+ | * distinct region in geography; a broad term that can include political divisions or regions associated with distinct political characteristics | ||
+ | */ | ||
+ | public static class Country extends TopicBase { | ||
+ | |||
+ | public String name; | ||
+ | public String wikidataid; | ||
+ | |||
+ | public String getName() { return name; } | ||
+ | public void setName(String pName) { name=pName; } | ||
+ | public String getWikidataid() { return wikidataid; } | ||
+ | public void setWikidataid(String pWikidataid) { wikidataid=pWikidataid; } | ||
+ | /** | ||
+ | * convert this Country to a JSON string | ||
+ | * @return the JSON representation | ||
+ | */ | ||
+ | public String toJson() { return JSON.toJSONString(this); } | ||
+ | |||
+ | /** | ||
+ | * convert this Country to a WikiSon string | ||
+ | * @return the WikiSon representation of this Country | ||
+ | */ | ||
+ | public String toWikiSon() { | ||
+ | String wikison= "{{Country\n"; | ||
+ | wikison+=toWikiSon("name",name); | ||
+ | wikison+=toWikiSon("wikidataid",wikidataid); | ||
+ | wikison+="}}\n"; | ||
+ | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this Country to a SiDIF string | ||
+ | * @return the SiDIF representation of this Country | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA Country\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("name",name,"text"); | ||
+ | siDIF+=propertySiDIF("wikidataid",wikidataid,"text"); | ||
+ | return siDIF; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * get the pageid for this topic | ||
+ | */ | ||
+ | public String getPageid() { return pageid; }; | ||
+ | |||
+ | /** | ||
+ | * default constructor for Country | ||
+ | */ | ||
+ | public Country() {} | ||
+ | |||
+ | /** | ||
+ | * construct a Country from the given Triple | ||
+ | * @param query - the TripleQuery to get the triples from | ||
+ | * @param pCountryTriple - the triple to construct me from | ||
+ | */ | ||
+ | public Country(TripleQuery query,Triple pCountryTriple) { | ||
+ | this(query,pCountryTriple.getSubject().toString()); | ||
+ | } // constructor | ||
+ | |||
+ | /** | ||
+ | * construct a Country from the given pageId | ||
+ | * @param query - the TripleQuery to get the triples from | ||
+ | * @param pageid - pageid | ||
+ | */ | ||
+ | public Country(TripleQuery query,String pageid) { | ||
+ | this.pageid=pageid; | ||
+ | Triple nameTriple=query.selectSingle(pageid,"name",null); | ||
+ | if (nameTriple==null) | ||
+ | nameTriple=query.selectSingle(pageid,"Property:Country_name",null); | ||
+ | if (nameTriple!=null) | ||
+ | name=nameTriple.getObject().toString(); | ||
+ | Triple wikidataidTriple=query.selectSingle(pageid,"wikidataid",null); | ||
+ | if (wikidataidTriple==null) | ||
+ | wikidataidTriple=query.selectSingle(pageid,"Property:Country_wikidataid",null); | ||
+ | if (wikidataidTriple!=null) | ||
+ | wikidataid=wikidataidTriple.getObject().toString(); | ||
+ | init(query); | ||
+ | } // constructor for Country | ||
+ | |||
+ | // >>>{user defined topic code}{Country}{Country} | ||
+ | // <<<{user defined topic code}{Country}{Country} | ||
+ | } // class Country | ||
+ | /** | ||
+ | * Manager for Country | ||
+ | */ | ||
+ | public static class CountryManager extends TopicBase { | ||
+ | |||
+ | public String topicName="Country"; | ||
+ | public transient List<Country> mCountrys=new ArrayList<Country>(); | ||
+ | public transient Map<String,Country> mCountryMap=new LinkedHashMap<String,Country>(); | ||
+ | |||
+ | /** | ||
+ | * get my Countries | ||
+ | */ | ||
+ | public List<Country> getCountries() { | ||
+ | List<Country> result=this.mCountrys; | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add a new Country | ||
+ | */ | ||
+ | public Country add(Country pCountry) { | ||
+ | mCountrys.add(pCountry); | ||
+ | mCountryMap.put(pCountry.getPageid(),pCountry); | ||
+ | return pCountry; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add a new Country from the given triple | ||
+ | */ | ||
+ | public Country add(TripleQuery query,Triple pCountryTriple) { | ||
+ | Country lCountry=new Country(query,pCountryTriple); | ||
+ | add(lCountry); | ||
+ | return lCountry; | ||
+ | } | ||
+ | |||
+ | // reinitialize my mCountry map | ||
+ | public void reinit() { | ||
+ | mCountryMap.clear(); | ||
+ | for (Country lCountry:mCountrys) { | ||
+ | mCountryMap.put(lCountry.getPageid(),lCountry); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // convert this manager to json format | ||
+ | public String toJson() { return JSON.toJSONString(this); } | ||
+ | |||
+ | // get a new manager from the given json string | ||
+ | public static CountryManager fromJson(String json) { | ||
+ | CountryManager result=JSON.parseObject(json, CountryManager.class); | ||
+ | result.reinit(); | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | // default constructor for Country Manager | ||
+ | public CountryManager() {} | ||
+ | |||
+ | // add Countries from the given query | ||
+ | public void addCountries(TripleQuery pCountryQuery,TripleQuery query) { | ||
+ | if (pCountryQuery!=null) { | ||
+ | for (Triple lCountryTriple:pCountryQuery.getTriples()) { | ||
+ | add(query,lCountryTriple); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // construct me from the given triple Query query | ||
+ | public CountryManager(TripleQuery query) { | ||
+ | // first query the SiDIF bases triplestore | ||
+ | TripleQuery lCountryQuery=query.query(null,"isA","Country"); | ||
+ | addCountries(lCountryQuery,query); | ||
+ | // then the SMW triplestore | ||
+ | lCountryQuery=query.query(null,"Property:IsA","Country"); | ||
+ | addCountries(lCountryQuery,query); | ||
+ | init(query); | ||
+ | } // constructor for Country Manager | ||
+ | |||
+ | // >>>{user defined topicmanager code}{Country}{Country} | ||
+ | // <<<{user defined topicmanager code}{Country}{Country} | ||
+ | } // class Country Manager | ||
+ | /** | ||
+ | * Region | ||
+ | * first-level administrative country subdivision e.g. Region/province | ||
+ | */ | ||
+ | public static class Region extends TopicBase { | ||
+ | |||
+ | public String name; | ||
+ | public String wikidataid; | ||
+ | |||
+ | public String getName() { return name; } | ||
+ | public void setName(String pName) { name=pName; } | ||
+ | public String getWikidataid() { return wikidataid; } | ||
+ | public void setWikidataid(String pWikidataid) { wikidataid=pWikidataid; } | ||
+ | /** | ||
+ | * convert this Region to a JSON string | ||
+ | * @return the JSON representation | ||
+ | */ | ||
+ | public String toJson() { return JSON.toJSONString(this); } | ||
+ | |||
+ | /** | ||
+ | * convert this Region to a WikiSon string | ||
+ | * @return the WikiSon representation of this Region | ||
+ | */ | ||
+ | public String toWikiSon() { | ||
+ | String wikison= "{{Region\n"; | ||
+ | wikison+=toWikiSon("name",name); | ||
+ | wikison+=toWikiSon("wikidataid",wikidataid); | ||
+ | wikison+="}}\n"; | ||
+ | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this Region to a SiDIF string | ||
+ | * @return the SiDIF representation of this Region | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA Region\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("name",name,"text"); | ||
+ | siDIF+=propertySiDIF("wikidataid",wikidataid,"text"); | ||
+ | return siDIF; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * get the pageid for this topic | ||
+ | */ | ||
+ | public String getPageid() { return pageid; }; | ||
+ | |||
+ | /** | ||
+ | * default constructor for Region | ||
+ | */ | ||
+ | public Region() {} | ||
+ | |||
+ | /** | ||
+ | * construct a Region from the given Triple | ||
+ | * @param query - the TripleQuery to get the triples from | ||
+ | * @param pRegionTriple - the triple to construct me from | ||
+ | */ | ||
+ | public Region(TripleQuery query,Triple pRegionTriple) { | ||
+ | this(query,pRegionTriple.getSubject().toString()); | ||
+ | } // constructor | ||
+ | |||
+ | /** | ||
+ | * construct a Region from the given pageId | ||
+ | * @param query - the TripleQuery to get the triples from | ||
+ | * @param pageid - pageid | ||
+ | */ | ||
+ | public Region(TripleQuery query,String pageid) { | ||
+ | this.pageid=pageid; | ||
+ | Triple nameTriple=query.selectSingle(pageid,"name",null); | ||
+ | if (nameTriple==null) | ||
+ | nameTriple=query.selectSingle(pageid,"Property:Region_name",null); | ||
+ | if (nameTriple!=null) | ||
+ | name=nameTriple.getObject().toString(); | ||
+ | Triple wikidataidTriple=query.selectSingle(pageid,"wikidataid",null); | ||
+ | if (wikidataidTriple==null) | ||
+ | wikidataidTriple=query.selectSingle(pageid,"Property:Region_wikidataid",null); | ||
+ | if (wikidataidTriple!=null) | ||
+ | wikidataid=wikidataidTriple.getObject().toString(); | ||
+ | init(query); | ||
+ | } // constructor for Region | ||
+ | |||
+ | // >>>{user defined topic code}{Region}{Region} | ||
+ | // <<<{user defined topic code}{Region}{Region} | ||
+ | } // class Region | ||
+ | /** | ||
+ | * Manager for Region | ||
+ | */ | ||
+ | public static class RegionManager extends TopicBase { | ||
+ | |||
+ | public String topicName="Region"; | ||
+ | public transient List<Region> mRegions=new ArrayList<Region>(); | ||
+ | public transient Map<String,Region> mRegionMap=new LinkedHashMap<String,Region>(); | ||
+ | |||
+ | /** | ||
+ | * get my Regions | ||
+ | */ | ||
+ | public List<Region> getRegions() { | ||
+ | List<Region> result=this.mRegions; | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add a new Region | ||
+ | */ | ||
+ | public Region add(Region pRegion) { | ||
+ | mRegions.add(pRegion); | ||
+ | mRegionMap.put(pRegion.getPageid(),pRegion); | ||
+ | return pRegion; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add a new Region from the given triple | ||
+ | */ | ||
+ | public Region add(TripleQuery query,Triple pRegionTriple) { | ||
+ | Region lRegion=new Region(query,pRegionTriple); | ||
+ | add(lRegion); | ||
+ | return lRegion; | ||
+ | } | ||
+ | |||
+ | // reinitialize my mRegion map | ||
+ | public void reinit() { | ||
+ | mRegionMap.clear(); | ||
+ | for (Region lRegion:mRegions) { | ||
+ | mRegionMap.put(lRegion.getPageid(),lRegion); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // convert this manager to json format | ||
+ | public String toJson() { return JSON.toJSONString(this); } | ||
+ | |||
+ | // get a new manager from the given json string | ||
+ | public static RegionManager fromJson(String json) { | ||
+ | RegionManager result=JSON.parseObject(json, RegionManager.class); | ||
+ | result.reinit(); | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | // default constructor for Region Manager | ||
+ | public RegionManager() {} | ||
+ | |||
+ | // add Regions from the given query | ||
+ | public void addRegions(TripleQuery pRegionQuery,TripleQuery query) { | ||
+ | if (pRegionQuery!=null) { | ||
+ | for (Triple lRegionTriple:pRegionQuery.getTriples()) { | ||
+ | add(query,lRegionTriple); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // construct me from the given triple Query query | ||
+ | public RegionManager(TripleQuery query) { | ||
+ | // first query the SiDIF bases triplestore | ||
+ | TripleQuery lRegionQuery=query.query(null,"isA","Region"); | ||
+ | addRegions(lRegionQuery,query); | ||
+ | // then the SMW triplestore | ||
+ | lRegionQuery=query.query(null,"Property:IsA","Region"); | ||
+ | addRegions(lRegionQuery,query); | ||
+ | init(query); | ||
+ | } // constructor for Region Manager | ||
+ | |||
+ | // >>>{user defined topicmanager code}{Region}{Region} | ||
+ | // <<<{user defined topicmanager code}{Region}{Region} | ||
+ | } // class Region Manager | ||
} | } | ||
</source> | </source> |
Latest revision as of 07:34, 6 October 2020
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
// convert double quotes to single quotes - FIXME - should we escape instead?
value=value.replace("\"","'");
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 my SiDIF representation
*/
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
/**
* EventSeries
* a series of Events
*/
public static class EventSeries extends TopicBase {
public String acronym;
public String homepage;
public String getAcronym() { return acronym; }
public void setAcronym(String pAcronym) { acronym=pAcronym; }
public String getHomepage() { return homepage; }
public void setHomepage(String pHomepage) { homepage=pHomepage; }
/**
* convert this EventSeries to a JSON string
* @return the JSON representation
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this EventSeries to a WikiSon string
* @return the WikiSon representation of this EventSeries
*/
public String toWikiSon() {
String wikison= "{{EventSeries\n";
wikison+=toWikiSon("acronym",acronym);
wikison+=toWikiSon("homepage",homepage);
wikison+="}}\n";
return wikison;
}
/**
* convert this EventSeries to a SiDIF string
* @return the SiDIF representation of this EventSeries
*/
public String toSiDIF() {
String siDIF = String.format("%s isA EventSeries\n",this.pageid);
siDIF+=propertySiDIF("acronym",acronym,"text");
siDIF+=propertySiDIF("homepage",homepage,"url");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for EventSeries
*/
public EventSeries() {}
/**
* construct a EventSeries from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pEventSeriesTriple - the triple to construct me from
*/
public EventSeries(TripleQuery query,Triple pEventSeriesTriple) {
this(query,pEventSeriesTriple.getSubject().toString());
} // constructor
/**
* construct a EventSeries from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public EventSeries(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple acronymTriple=query.selectSingle(pageid,"acronym",null);
if (acronymTriple==null)
acronymTriple=query.selectSingle(pageid,"Property:EventSeries_acronym",null);
if (acronymTriple!=null)
acronym=acronymTriple.getObject().toString();
Triple homepageTriple=query.selectSingle(pageid,"homepage",null);
if (homepageTriple==null)
homepageTriple=query.selectSingle(pageid,"Property:EventSeries_homepage",null);
if (homepageTriple!=null)
homepage=homepageTriple.getObject().toString();
init(query);
} // constructor for EventSeries
// >>>{user defined topic code}{EventSeries}{EventSeries}
// <<<{user defined topic code}{EventSeries}{EventSeries}
} // class EventSeries
/**
* Manager for EventSeries
*/
public static class EventSeriesManager extends TopicBase {
public String topicName="EventSeries";
public transient List<EventSeries> mEventSeriess=new ArrayList<EventSeries>();
public transient Map<String,EventSeries> mEventSeriesMap=new LinkedHashMap<String,EventSeries>();
/**
* get my EventSeries
*/
public List<EventSeries> getEventSeries() {
List<EventSeries> result=this.mEventSeriess;
return result;
}
/**
* add a new EventSeries
*/
public EventSeries add(EventSeries pEventSeries) {
mEventSeriess.add(pEventSeries);
mEventSeriesMap.put(pEventSeries.getPageid(),pEventSeries);
return pEventSeries;
}
/**
* add a new EventSeries from the given triple
*/
public EventSeries add(TripleQuery query,Triple pEventSeriesTriple) {
EventSeries lEventSeries=new EventSeries(query,pEventSeriesTriple);
add(lEventSeries);
return lEventSeries;
}
// reinitialize my mEventSeries map
public void reinit() {
mEventSeriesMap.clear();
for (EventSeries lEventSeries:mEventSeriess) {
mEventSeriesMap.put(lEventSeries.getPageid(),lEventSeries);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static EventSeriesManager fromJson(String json) {
EventSeriesManager result=JSON.parseObject(json, EventSeriesManager.class);
result.reinit();
return result;
}
// default constructor for EventSeries Manager
public EventSeriesManager() {}
// add EventSeries from the given query
public void addEventSeries(TripleQuery pEventSeriesQuery,TripleQuery query) {
if (pEventSeriesQuery!=null) {
for (Triple lEventSeriesTriple:pEventSeriesQuery.getTriples()) {
add(query,lEventSeriesTriple);
}
}
}
// construct me from the given triple Query query
public EventSeriesManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lEventSeriesQuery=query.query(null,"isA","EventSeries");
addEventSeries(lEventSeriesQuery,query);
// then the SMW triplestore
lEventSeriesQuery=query.query(null,"Property:IsA","EventSeries");
addEventSeries(lEventSeriesQuery,query);
init(query);
} // constructor for EventSeries Manager
// >>>{user defined topicmanager code}{EventSeries}{EventSeries}
// <<<{user defined topicmanager code}{EventSeries}{EventSeries}
} // class EventSeries Manager
/**
* Event
* a meeting of researchers at a specific time and place
*/
public static class Event extends TopicBase {
public String acronym;
public String homepage;
public String wikidataid;
public String series;
public String city;
public String region;
public String country;
public String getAcronym() { return acronym; }
public void setAcronym(String pAcronym) { acronym=pAcronym; }
public String getHomepage() { return homepage; }
public void setHomepage(String pHomepage) { homepage=pHomepage; }
public String getWikidataid() { return wikidataid; }
public void setWikidataid(String pWikidataid) { wikidataid=pWikidataid; }
public String getSeries() { return series; }
public void setSeries(String pSeries) { series=pSeries; }
public String getCity() { return city; }
public void setCity(String pCity) { city=pCity; }
public String getRegion() { return region; }
public void setRegion(String pRegion) { region=pRegion; }
public String getCountry() { return country; }
public void setCountry(String pCountry) { country=pCountry; }
/**
* convert this Event to a JSON string
* @return the JSON representation
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Event to a WikiSon string
* @return the WikiSon representation of this Event
*/
public String toWikiSon() {
String wikison= "{{Event\n";
wikison+=toWikiSon("acronym",acronym);
wikison+=toWikiSon("homepage",homepage);
wikison+=toWikiSon("wikidataid",wikidataid);
wikison+=toWikiSon("series",series);
wikison+=toWikiSon("city",city);
wikison+=toWikiSon("region",region);
wikison+=toWikiSon("country",country);
wikison+="}}\n";
return wikison;
}
/**
* convert this Event to a SiDIF string
* @return the SiDIF representation of this Event
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Event\n",this.pageid);
siDIF+=propertySiDIF("acronym",acronym,"text");
siDIF+=propertySiDIF("homepage",homepage,"url");
siDIF+=propertySiDIF("wikidataid",wikidataid,"text");
siDIF+=propertySiDIF("series",series,"Page");
siDIF+=propertySiDIF("city",city,"Page");
siDIF+=propertySiDIF("region",region,"Page");
siDIF+=propertySiDIF("country",country,"Page");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Event
*/
public Event() {}
/**
* construct a Event from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pEventTriple - the triple to construct me from
*/
public Event(TripleQuery query,Triple pEventTriple) {
this(query,pEventTriple.getSubject().toString());
} // constructor
/**
* construct a Event from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Event(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple acronymTriple=query.selectSingle(pageid,"acronym",null);
if (acronymTriple==null)
acronymTriple=query.selectSingle(pageid,"Property:Event_acronym",null);
if (acronymTriple!=null)
acronym=acronymTriple.getObject().toString();
Triple homepageTriple=query.selectSingle(pageid,"homepage",null);
if (homepageTriple==null)
homepageTriple=query.selectSingle(pageid,"Property:Event_homepage",null);
if (homepageTriple!=null)
homepage=homepageTriple.getObject().toString();
Triple wikidataidTriple=query.selectSingle(pageid,"wikidataid",null);
if (wikidataidTriple==null)
wikidataidTriple=query.selectSingle(pageid,"Property:Event_wikidataid",null);
if (wikidataidTriple!=null)
wikidataid=wikidataidTriple.getObject().toString();
Triple seriesTriple=query.selectSingle(pageid,"series",null);
if (seriesTriple==null)
seriesTriple=query.selectSingle(pageid,"Property:Event_series",null);
if (seriesTriple!=null)
series=seriesTriple.getObject().toString();
Triple cityTriple=query.selectSingle(pageid,"city",null);
if (cityTriple==null)
cityTriple=query.selectSingle(pageid,"Property:Event_city",null);
if (cityTriple!=null)
city=cityTriple.getObject().toString();
Triple regionTriple=query.selectSingle(pageid,"region",null);
if (regionTriple==null)
regionTriple=query.selectSingle(pageid,"Property:Event_region",null);
if (regionTriple!=null)
region=regionTriple.getObject().toString();
Triple countryTriple=query.selectSingle(pageid,"country",null);
if (countryTriple==null)
countryTriple=query.selectSingle(pageid,"Property:Event_country",null);
if (countryTriple!=null)
country=countryTriple.getObject().toString();
init(query);
} // constructor for Event
// >>>{user defined topic code}{Event}{Event}
// <<<{user defined topic code}{Event}{Event}
} // class Event
/**
* Manager for Event
*/
public static class EventManager extends TopicBase {
public String topicName="Event";
public transient List<Event> mEvents=new ArrayList<Event>();
public transient Map<String,Event> mEventMap=new LinkedHashMap<String,Event>();
/**
* get my Events
*/
public List<Event> getEvents() {
List<Event> result=this.mEvents;
return result;
}
/**
* add a new Event
*/
public Event add(Event pEvent) {
mEvents.add(pEvent);
mEventMap.put(pEvent.getPageid(),pEvent);
return pEvent;
}
/**
* add a new Event from the given triple
*/
public Event add(TripleQuery query,Triple pEventTriple) {
Event lEvent=new Event(query,pEventTriple);
add(lEvent);
return lEvent;
}
// reinitialize my mEvent map
public void reinit() {
mEventMap.clear();
for (Event lEvent:mEvents) {
mEventMap.put(lEvent.getPageid(),lEvent);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static EventManager fromJson(String json) {
EventManager result=JSON.parseObject(json, EventManager.class);
result.reinit();
return result;
}
// default constructor for Event Manager
public EventManager() {}
// add Events from the given query
public void addEvents(TripleQuery pEventQuery,TripleQuery query) {
if (pEventQuery!=null) {
for (Triple lEventTriple:pEventQuery.getTriples()) {
add(query,lEventTriple);
}
}
}
// construct me from the given triple Query query
public EventManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lEventQuery=query.query(null,"isA","Event");
addEvents(lEventQuery,query);
// then the SMW triplestore
lEventQuery=query.query(null,"Property:IsA","Event");
addEvents(lEventQuery,query);
init(query);
} // constructor for Event Manager
// >>>{user defined topicmanager code}{Event}{Event}
// <<<{user defined topicmanager code}{Event}{Event}
} // class Event Manager
/**
* City
* large permanent human settlement
*/
public static class City extends TopicBase {
public String name;
public String wikidataid;
public String getName() { return name; }
public void setName(String pName) { name=pName; }
public String getWikidataid() { return wikidataid; }
public void setWikidataid(String pWikidataid) { wikidataid=pWikidataid; }
/**
* convert this City to a JSON string
* @return the JSON representation
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this City to a WikiSon string
* @return the WikiSon representation of this City
*/
public String toWikiSon() {
String wikison= "{{City\n";
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("wikidataid",wikidataid);
wikison+="}}\n";
return wikison;
}
/**
* convert this City to a SiDIF string
* @return the SiDIF representation of this City
*/
public String toSiDIF() {
String siDIF = String.format("%s isA City\n",this.pageid);
siDIF+=propertySiDIF("name",name,"text");
siDIF+=propertySiDIF("wikidataid",wikidataid,"text");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for City
*/
public City() {}
/**
* construct a City from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pCityTriple - the triple to construct me from
*/
public City(TripleQuery query,Triple pCityTriple) {
this(query,pCityTriple.getSubject().toString());
} // constructor
/**
* construct a City from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public City(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:City_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple wikidataidTriple=query.selectSingle(pageid,"wikidataid",null);
if (wikidataidTriple==null)
wikidataidTriple=query.selectSingle(pageid,"Property:City_wikidataid",null);
if (wikidataidTriple!=null)
wikidataid=wikidataidTriple.getObject().toString();
init(query);
} // constructor for City
// >>>{user defined topic code}{City}{City}
// <<<{user defined topic code}{City}{City}
} // class City
/**
* Manager for City
*/
public static class CityManager extends TopicBase {
public String topicName="City";
public transient List<City> mCitys=new ArrayList<City>();
public transient Map<String,City> mCityMap=new LinkedHashMap<String,City>();
/**
* get my Cities
*/
public List<City> getCities() {
List<City> result=this.mCitys;
return result;
}
/**
* add a new City
*/
public City add(City pCity) {
mCitys.add(pCity);
mCityMap.put(pCity.getPageid(),pCity);
return pCity;
}
/**
* add a new City from the given triple
*/
public City add(TripleQuery query,Triple pCityTriple) {
City lCity=new City(query,pCityTriple);
add(lCity);
return lCity;
}
// reinitialize my mCity map
public void reinit() {
mCityMap.clear();
for (City lCity:mCitys) {
mCityMap.put(lCity.getPageid(),lCity);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static CityManager fromJson(String json) {
CityManager result=JSON.parseObject(json, CityManager.class);
result.reinit();
return result;
}
// default constructor for City Manager
public CityManager() {}
// add Cities from the given query
public void addCities(TripleQuery pCityQuery,TripleQuery query) {
if (pCityQuery!=null) {
for (Triple lCityTriple:pCityQuery.getTriples()) {
add(query,lCityTriple);
}
}
}
// construct me from the given triple Query query
public CityManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lCityQuery=query.query(null,"isA","City");
addCities(lCityQuery,query);
// then the SMW triplestore
lCityQuery=query.query(null,"Property:IsA","City");
addCities(lCityQuery,query);
init(query);
} // constructor for City Manager
// >>>{user defined topicmanager code}{City}{City}
// <<<{user defined topicmanager code}{City}{City}
} // class City Manager
/**
* Country
* distinct region in geography; a broad term that can include political divisions or regions associated with distinct political characteristics
*/
public static class Country extends TopicBase {
public String name;
public String wikidataid;
public String getName() { return name; }
public void setName(String pName) { name=pName; }
public String getWikidataid() { return wikidataid; }
public void setWikidataid(String pWikidataid) { wikidataid=pWikidataid; }
/**
* convert this Country to a JSON string
* @return the JSON representation
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Country to a WikiSon string
* @return the WikiSon representation of this Country
*/
public String toWikiSon() {
String wikison= "{{Country\n";
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("wikidataid",wikidataid);
wikison+="}}\n";
return wikison;
}
/**
* convert this Country to a SiDIF string
* @return the SiDIF representation of this Country
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Country\n",this.pageid);
siDIF+=propertySiDIF("name",name,"text");
siDIF+=propertySiDIF("wikidataid",wikidataid,"text");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Country
*/
public Country() {}
/**
* construct a Country from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pCountryTriple - the triple to construct me from
*/
public Country(TripleQuery query,Triple pCountryTriple) {
this(query,pCountryTriple.getSubject().toString());
} // constructor
/**
* construct a Country from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Country(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:Country_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple wikidataidTriple=query.selectSingle(pageid,"wikidataid",null);
if (wikidataidTriple==null)
wikidataidTriple=query.selectSingle(pageid,"Property:Country_wikidataid",null);
if (wikidataidTriple!=null)
wikidataid=wikidataidTriple.getObject().toString();
init(query);
} // constructor for Country
// >>>{user defined topic code}{Country}{Country}
// <<<{user defined topic code}{Country}{Country}
} // class Country
/**
* Manager for Country
*/
public static class CountryManager extends TopicBase {
public String topicName="Country";
public transient List<Country> mCountrys=new ArrayList<Country>();
public transient Map<String,Country> mCountryMap=new LinkedHashMap<String,Country>();
/**
* get my Countries
*/
public List<Country> getCountries() {
List<Country> result=this.mCountrys;
return result;
}
/**
* add a new Country
*/
public Country add(Country pCountry) {
mCountrys.add(pCountry);
mCountryMap.put(pCountry.getPageid(),pCountry);
return pCountry;
}
/**
* add a new Country from the given triple
*/
public Country add(TripleQuery query,Triple pCountryTriple) {
Country lCountry=new Country(query,pCountryTriple);
add(lCountry);
return lCountry;
}
// reinitialize my mCountry map
public void reinit() {
mCountryMap.clear();
for (Country lCountry:mCountrys) {
mCountryMap.put(lCountry.getPageid(),lCountry);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static CountryManager fromJson(String json) {
CountryManager result=JSON.parseObject(json, CountryManager.class);
result.reinit();
return result;
}
// default constructor for Country Manager
public CountryManager() {}
// add Countries from the given query
public void addCountries(TripleQuery pCountryQuery,TripleQuery query) {
if (pCountryQuery!=null) {
for (Triple lCountryTriple:pCountryQuery.getTriples()) {
add(query,lCountryTriple);
}
}
}
// construct me from the given triple Query query
public CountryManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lCountryQuery=query.query(null,"isA","Country");
addCountries(lCountryQuery,query);
// then the SMW triplestore
lCountryQuery=query.query(null,"Property:IsA","Country");
addCountries(lCountryQuery,query);
init(query);
} // constructor for Country Manager
// >>>{user defined topicmanager code}{Country}{Country}
// <<<{user defined topicmanager code}{Country}{Country}
} // class Country Manager
/**
* Region
* first-level administrative country subdivision e.g. Region/province
*/
public static class Region extends TopicBase {
public String name;
public String wikidataid;
public String getName() { return name; }
public void setName(String pName) { name=pName; }
public String getWikidataid() { return wikidataid; }
public void setWikidataid(String pWikidataid) { wikidataid=pWikidataid; }
/**
* convert this Region to a JSON string
* @return the JSON representation
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Region to a WikiSon string
* @return the WikiSon representation of this Region
*/
public String toWikiSon() {
String wikison= "{{Region\n";
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("wikidataid",wikidataid);
wikison+="}}\n";
return wikison;
}
/**
* convert this Region to a SiDIF string
* @return the SiDIF representation of this Region
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Region\n",this.pageid);
siDIF+=propertySiDIF("name",name,"text");
siDIF+=propertySiDIF("wikidataid",wikidataid,"text");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Region
*/
public Region() {}
/**
* construct a Region from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pRegionTriple - the triple to construct me from
*/
public Region(TripleQuery query,Triple pRegionTriple) {
this(query,pRegionTriple.getSubject().toString());
} // constructor
/**
* construct a Region from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Region(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:Region_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple wikidataidTriple=query.selectSingle(pageid,"wikidataid",null);
if (wikidataidTriple==null)
wikidataidTriple=query.selectSingle(pageid,"Property:Region_wikidataid",null);
if (wikidataidTriple!=null)
wikidataid=wikidataidTriple.getObject().toString();
init(query);
} // constructor for Region
// >>>{user defined topic code}{Region}{Region}
// <<<{user defined topic code}{Region}{Region}
} // class Region
/**
* Manager for Region
*/
public static class RegionManager extends TopicBase {
public String topicName="Region";
public transient List<Region> mRegions=new ArrayList<Region>();
public transient Map<String,Region> mRegionMap=new LinkedHashMap<String,Region>();
/**
* get my Regions
*/
public List<Region> getRegions() {
List<Region> result=this.mRegions;
return result;
}
/**
* add a new Region
*/
public Region add(Region pRegion) {
mRegions.add(pRegion);
mRegionMap.put(pRegion.getPageid(),pRegion);
return pRegion;
}
/**
* add a new Region from the given triple
*/
public Region add(TripleQuery query,Triple pRegionTriple) {
Region lRegion=new Region(query,pRegionTriple);
add(lRegion);
return lRegion;
}
// reinitialize my mRegion map
public void reinit() {
mRegionMap.clear();
for (Region lRegion:mRegions) {
mRegionMap.put(lRegion.getPageid(),lRegion);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static RegionManager fromJson(String json) {
RegionManager result=JSON.parseObject(json, RegionManager.class);
result.reinit();
return result;
}
// default constructor for Region Manager
public RegionManager() {}
// add Regions from the given query
public void addRegions(TripleQuery pRegionQuery,TripleQuery query) {
if (pRegionQuery!=null) {
for (Triple lRegionTriple:pRegionQuery.getTriples()) {
add(query,lRegionTriple);
}
}
}
// construct me from the given triple Query query
public RegionManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lRegionQuery=query.query(null,"isA","Region");
addRegions(lRegionQuery,query);
// then the SMW triplestore
lRegionQuery=query.query(null,"Property:IsA","Region");
addRegions(lRegionQuery,query);
init(query);
} // constructor for Region Manager
// >>>{user defined topicmanager code}{Region}{Region}
// <<<{user defined topicmanager code}{Region}{Region}
} // class Region Manager
}