Difference between revisions of "Concept:Action/Java"
Jump to navigation
Jump to search
(created by WikiTask 2017-10-03T17:25:05Z) |
m (created by WikiTask 2019-10-11T04:57:42Z) |
||
Line 37: | Line 37: | ||
/** | /** | ||
− | * get the | + | * 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 | + | // 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 | ||
− | + | // 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 the SiDIF property line | ||
Line 96: | Line 99: | ||
} // TopicBase | } // TopicBase | ||
/** | /** | ||
− | * | + | * SMW_Type |
− | * A | + | * an SMW_Type is a data type which determines the possible values for that type e.g. a Boolean can hold true/false values while a Number can hold 3.1459 or 20. A Page can hold the name of a Wiki page see https://semantic-mediawiki.org/wiki/Help:List_of_datatypes |
*/ | */ | ||
− | public static class | + | public static class SMW_Type extends TopicBase { |
− | public String | + | public String type; |
− | public String | + | public String typepage; |
− | public String | + | public String usedByProperties; |
+ | public String documentation; | ||
+ | public String helppage; | ||
+ | public String javaType; | ||
+ | public String id; | ||
− | public String | + | public String getType() { return type; } |
− | public void | + | public void setType(String pType) { type=pType; } |
− | public String | + | public String getTypepage() { return typepage; } |
− | public void | + | public void setTypepage(String pTypepage) { typepage=pTypepage; } |
− | public String | + | public String getUsedByProperties() { return usedByProperties; } |
− | public void | + | public void setUsedByProperties(String pUsedByProperties) { usedByProperties=pUsedByProperties; } |
+ | public String getDocumentation() { return documentation; } | ||
+ | public void setDocumentation(String pDocumentation) { documentation=pDocumentation; } | ||
+ | public String getHelppage() { return helppage; } | ||
+ | public void setHelppage(String pHelppage) { helppage=pHelppage; } | ||
+ | public String getJavaType() { return javaType; } | ||
+ | public void setJavaType(String pJavaType) { javaType=pJavaType; } | ||
+ | public String getId() { return id; } | ||
+ | public void setId(String pId) { id=pId; } | ||
/** | /** | ||
− | * convert this | + | * convert this SMW_Type to a JSON string |
*/ | */ | ||
public String toJson() { return JSON.toJSONString(this); } | public String toJson() { return JSON.toJSONString(this); } | ||
/** | /** | ||
− | * convert this | + | * convert this SMW_Type to a WikiSon string |
+ | * @return the WikiSon representation of this SMW_Type | ||
*/ | */ | ||
public String toWikiSon() { | public String toWikiSon() { | ||
− | String wikison= "{{ | + | String wikison= "{{SMW_Type\n"; |
− | wikison+=toWikiSon(" | + | wikison+=toWikiSon("type",type); |
− | wikison+=toWikiSon(" | + | wikison+=toWikiSon("typepage",typepage); |
− | wikison+=toWikiSon(" | + | wikison+=toWikiSon("usedByProperties",usedByProperties); |
+ | wikison+=toWikiSon("documentation",documentation); | ||
+ | wikison+=toWikiSon("helppage",helppage); | ||
+ | wikison+=toWikiSon("javaType",javaType); | ||
+ | wikison+=toWikiSon("id",id); | ||
wikison+="}}\n"; | wikison+="}}\n"; | ||
return wikison; | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this SMW_Type to a SiDIF string | ||
+ | * @return the SiDIF representation of this SMW_Type | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA SMW_Type\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("type",type,"Text"); | ||
+ | siDIF+=propertySiDIF("typepage",typepage,"Page"); | ||
+ | siDIF+=propertySiDIF("usedByProperties",usedByProperties,"Page"); | ||
+ | siDIF+=propertySiDIF("documentation",documentation,"Text"); | ||
+ | siDIF+=propertySiDIF("helppage",helppage,"URL"); | ||
+ | siDIF+=propertySiDIF("javaType",javaType,"Text"); | ||
+ | siDIF+=propertySiDIF("id",id,"Text"); | ||
+ | return siDIF; | ||
} | } | ||
Line 134: | Line 170: | ||
/** | /** | ||
− | * default constructor for | + | * default constructor for SMW_Type |
*/ | */ | ||
− | public | + | public SMW_Type() {} |
/** | /** | ||
− | * construct a | + | * construct a SMW_Type from the given Triple |
* @param query - the TripleQuery to get the triples from | * @param query - the TripleQuery to get the triples from | ||
− | * @param | + | * @param pSMW_TypeTriple - the triple to construct me from |
*/ | */ | ||
− | public | + | public SMW_Type(TripleQuery query,Triple pSMW_TypeTriple) { |
− | this(query, | + | this(query,pSMW_TypeTriple.getSubject().toString()); |
} // constructor | } // constructor | ||
/** | /** | ||
− | * construct a | + | * construct a SMW_Type from the given pageId |
* @param query - the TripleQuery to get the triples from | * @param query - the TripleQuery to get the triples from | ||
* @param pageid - pageid | * @param pageid - pageid | ||
*/ | */ | ||
− | public | + | public SMW_Type(TripleQuery query,String pageid) { |
this.pageid=pageid; | this.pageid=pageid; | ||
− | Triple | + | Triple typeTriple=query.selectSingle(pageid,"type",null); |
− | if ( | + | if (typeTriple==null) |
− | + | typeTriple=query.selectSingle(pageid,"Property:SMW_Type_type",null); | |
− | if ( | + | if (typeTriple!=null) |
− | + | type=typeTriple.getObject().toString(); | |
− | Triple | + | Triple typepageTriple=query.selectSingle(pageid,"typepage",null); |
− | if ( | + | if (typepageTriple==null) |
− | + | typepageTriple=query.selectSingle(pageid,"Property:SMW_Type_typepage",null); | |
− | if ( | + | if (typepageTriple!=null) |
− | + | typepage=typepageTriple.getObject().toString(); | |
− | Triple | + | Triple usedByPropertiesTriple=query.selectSingle(pageid,"usedByProperties",null); |
− | if ( | + | if (usedByPropertiesTriple==null) |
− | + | usedByPropertiesTriple=query.selectSingle(pageid,"Property:SMW_Type_usedByProperties",null); | |
− | if ( | + | if (usedByPropertiesTriple!=null) |
− | + | usedByProperties=usedByPropertiesTriple.getObject().toString(); | |
+ | Triple documentationTriple=query.selectSingle(pageid,"documentation",null); | ||
+ | if (documentationTriple==null) | ||
+ | documentationTriple=query.selectSingle(pageid,"Property:SMW_Type_documentation",null); | ||
+ | if (documentationTriple!=null) | ||
+ | documentation=documentationTriple.getObject().toString(); | ||
+ | Triple helppageTriple=query.selectSingle(pageid,"helppage",null); | ||
+ | if (helppageTriple==null) | ||
+ | helppageTriple=query.selectSingle(pageid,"Property:SMW_Type_helppage",null); | ||
+ | if (helppageTriple!=null) | ||
+ | helppage=helppageTriple.getObject().toString(); | ||
+ | Triple javaTypeTriple=query.selectSingle(pageid,"javaType",null); | ||
+ | if (javaTypeTriple==null) | ||
+ | javaTypeTriple=query.selectSingle(pageid,"Property:SMW_Type_javaType",null); | ||
+ | if (javaTypeTriple!=null) | ||
+ | javaType=javaTypeTriple.getObject().toString(); | ||
+ | Triple idTriple=query.selectSingle(pageid,"id",null); | ||
+ | if (idTriple==null) | ||
+ | idTriple=query.selectSingle(pageid,"Property:SMW_Type_id",null); | ||
+ | if (idTriple!=null) | ||
+ | id=idTriple.getObject().toString(); | ||
init(query); | init(query); | ||
− | } // constructor for | + | } // constructor for SMW_Type |
− | // >>>{user defined topic code}{ | + | // >>>{user defined topic code}{SMW_Type}{SMW_Type} |
− | // <<<{user defined topic code}{ | + | // <<<{user defined topic code}{SMW_Type}{SMW_Type} |
− | } // class | + | } // class SMW_Type |
/** | /** | ||
− | * Manager for | + | * Manager for SMW_Type |
*/ | */ | ||
− | public static class | + | public static class SMW_TypeManager extends TopicBase { |
− | public String topicName=" | + | public String topicName="SMW_Type"; |
− | public transient List< | + | public transient List<SMW_Type> mSMW_Types=new ArrayList<SMW_Type>(); |
− | public transient Map<String, | + | public transient Map<String,SMW_Type> mSMW_TypeMap=new LinkedHashMap<String,SMW_Type>(); |
/** | /** | ||
− | * get my | + | * get my SMW_Types |
*/ | */ | ||
− | public List< | + | public List<SMW_Type> getSMW_Types() { |
− | List< | + | List<SMW_Type> result=this.mSMW_Types; |
return result; | return result; | ||
} | } | ||
/** | /** | ||
− | * add a new | + | * add a new SMW_Type |
*/ | */ | ||
− | public | + | public SMW_Type add(SMW_Type pSMW_Type) { |
− | + | mSMW_Types.add(pSMW_Type); | |
− | + | mSMW_TypeMap.put(pSMW_Type.getPageid(),pSMW_Type); | |
− | return | + | return pSMW_Type; |
} | } | ||
/** | /** | ||
− | * add a new | + | * add a new SMW_Type from the given triple |
*/ | */ | ||
− | public | + | public SMW_Type add(TripleQuery query,Triple pSMW_TypeTriple) { |
− | + | SMW_Type lSMW_Type=new SMW_Type(query,pSMW_TypeTriple); | |
− | add( | + | add(lSMW_Type); |
− | return | + | return lSMW_Type; |
} | } | ||
− | // reinitialize my | + | // reinitialize my mSMW_Type map |
public void reinit() { | public void reinit() { | ||
− | + | mSMW_TypeMap.clear(); | |
− | for ( | + | for (SMW_Type lSMW_Type:mSMW_Types) { |
− | + | mSMW_TypeMap.put(lSMW_Type.getPageid(),lSMW_Type); | |
} | } | ||
} | } | ||
Line 222: | Line 278: | ||
// get a new manager from the given json string | // get a new manager from the given json string | ||
− | public static | + | public static SMW_TypeManager fromJson(String json) { |
− | + | SMW_TypeManager result=JSON.parseObject(json, SMW_TypeManager.class); | |
result.reinit(); | result.reinit(); | ||
return result; | return result; | ||
} | } | ||
− | // default constructor for | + | // default constructor for SMW_Type Manager |
− | public | + | public SMW_TypeManager() {} |
− | // add | + | // add SMW_Types from the given query |
− | public void | + | public void addSMW_Types(TripleQuery pSMW_TypeQuery,TripleQuery query) { |
− | if ( | + | if (pSMW_TypeQuery!=null) { |
− | for (Triple | + | for (Triple lSMW_TypeTriple:pSMW_TypeQuery.getTriples()) { |
− | add(query, | + | add(query,lSMW_TypeTriple); |
} | } | ||
} | } | ||
Line 241: | Line 297: | ||
// construct me from the given triple Query query | // construct me from the given triple Query query | ||
− | public | + | public SMW_TypeManager(TripleQuery query) { |
// first query the SiDIF bases triplestore | // first query the SiDIF bases triplestore | ||
− | TripleQuery | + | TripleQuery lSMW_TypeQuery=query.query(null,"isA","SMW_Type"); |
− | + | addSMW_Types(lSMW_TypeQuery,query); | |
// then the SMW triplestore | // then the SMW triplestore | ||
− | + | lSMW_TypeQuery=query.query(null,"Property:IsA","SMW_Type"); | |
− | + | addSMW_Types(lSMW_TypeQuery,query); | |
init(query); | init(query); | ||
− | } // constructor for | + | } // constructor for SMW_Type Manager |
− | // >>>{user defined topicmanager code}{ | + | // >>>{user defined topicmanager code}{SMW_Type}{SMW_Type} |
− | // <<<{user defined topicmanager code}{ | + | // <<<{user defined topicmanager code}{SMW_Type}{SMW_Type} |
− | } // class | + | } // class SMW_Type Manager |
/** | /** | ||
* Property | * Property | ||
Line 260: | Line 316: | ||
public static class Property extends TopicBase { | public static class Property extends TopicBase { | ||
− | |||
− | |||
− | |||
public String index; | public String index; | ||
public String sortPos; | public String sortPos; | ||
− | |||
public String mandatory; | public String mandatory; | ||
− | |||
− | |||
public String uploadable; | public String uploadable; | ||
public String defaultValue; | public String defaultValue; | ||
public String inputType; | public String inputType; | ||
public String allowedValues; | public String allowedValues; | ||
− | |||
public String values_from; | public String values_from; | ||
public String showInGrid; | public String showInGrid; | ||
public String isLink; | public String isLink; | ||
+ | public String type; | ||
+ | public String name; | ||
+ | public String label; | ||
+ | public String primaryKey; | ||
+ | public String namespace; | ||
+ | public String size; | ||
+ | public String documentation; | ||
public String nullable; | public String nullable; | ||
public String topic; | public String topic; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
public String getIndex() { return index; } | public String getIndex() { return index; } | ||
public void setIndex(String pIndex) { index=pIndex; } | public void setIndex(String pIndex) { index=pIndex; } | ||
public String getSortPos() { return sortPos; } | public String getSortPos() { return sortPos; } | ||
public void setSortPos(String pSortPos) { sortPos=pSortPos; } | public void setSortPos(String pSortPos) { sortPos=pSortPos; } | ||
− | |||
− | |||
public String getMandatory() { return mandatory; } | public String getMandatory() { return mandatory; } | ||
public void setMandatory(String pMandatory) { mandatory=pMandatory; } | public void setMandatory(String pMandatory) { mandatory=pMandatory; } | ||
− | |||
− | |||
− | |||
− | |||
public String getUploadable() { return uploadable; } | public String getUploadable() { return uploadable; } | ||
public void setUploadable(String pUploadable) { uploadable=pUploadable; } | public void setUploadable(String pUploadable) { uploadable=pUploadable; } | ||
Line 306: | Line 350: | ||
public String getAllowedValues() { return allowedValues; } | public String getAllowedValues() { return allowedValues; } | ||
public void setAllowedValues(String pAllowedValues) { allowedValues=pAllowedValues; } | public void setAllowedValues(String pAllowedValues) { allowedValues=pAllowedValues; } | ||
− | |||
− | |||
public String getValues_from() { return values_from; } | public String getValues_from() { return values_from; } | ||
public void setValues_from(String pValues_from) { values_from=pValues_from; } | public void setValues_from(String pValues_from) { values_from=pValues_from; } | ||
Line 314: | Line 356: | ||
public String getIsLink() { return isLink; } | public String getIsLink() { return isLink; } | ||
public void setIsLink(String pIsLink) { isLink=pIsLink; } | public void setIsLink(String pIsLink) { isLink=pIsLink; } | ||
+ | public String getType() { return type; } | ||
+ | public void setType(String pType) { type=pType; } | ||
+ | public String getName() { return name; } | ||
+ | public void setName(String pName) { name=pName; } | ||
+ | public String getLabel() { return label; } | ||
+ | public void setLabel(String pLabel) { label=pLabel; } | ||
+ | public String getPrimaryKey() { return primaryKey; } | ||
+ | public void setPrimaryKey(String pPrimaryKey) { primaryKey=pPrimaryKey; } | ||
+ | public String getNamespace() { return namespace; } | ||
+ | public void setNamespace(String pNamespace) { namespace=pNamespace; } | ||
+ | public String getSize() { return size; } | ||
+ | public void setSize(String pSize) { size=pSize; } | ||
+ | public String getDocumentation() { return documentation; } | ||
+ | public void setDocumentation(String pDocumentation) { documentation=pDocumentation; } | ||
public String getNullable() { return nullable; } | public String getNullable() { return nullable; } | ||
public void setNullable(String pNullable) { nullable=pNullable; } | public void setNullable(String pNullable) { nullable=pNullable; } | ||
Line 325: | Line 381: | ||
/** | /** | ||
* convert this Property to a WikiSon string | * convert this Property to a WikiSon string | ||
+ | * @return the WikiSon representation of this Property | ||
*/ | */ | ||
public String toWikiSon() { | public String toWikiSon() { | ||
String wikison= "{{Property\n"; | String wikison= "{{Property\n"; | ||
− | |||
− | |||
− | |||
wikison+=toWikiSon("index",index); | wikison+=toWikiSon("index",index); | ||
wikison+=toWikiSon("sortPos",sortPos); | wikison+=toWikiSon("sortPos",sortPos); | ||
− | |||
wikison+=toWikiSon("mandatory",mandatory); | wikison+=toWikiSon("mandatory",mandatory); | ||
− | |||
− | |||
wikison+=toWikiSon("uploadable",uploadable); | wikison+=toWikiSon("uploadable",uploadable); | ||
wikison+=toWikiSon("defaultValue",defaultValue); | wikison+=toWikiSon("defaultValue",defaultValue); | ||
wikison+=toWikiSon("inputType",inputType); | wikison+=toWikiSon("inputType",inputType); | ||
wikison+=toWikiSon("allowedValues",allowedValues); | wikison+=toWikiSon("allowedValues",allowedValues); | ||
− | |||
wikison+=toWikiSon("values_from",values_from); | wikison+=toWikiSon("values_from",values_from); | ||
wikison+=toWikiSon("showInGrid",showInGrid); | wikison+=toWikiSon("showInGrid",showInGrid); | ||
wikison+=toWikiSon("isLink",isLink); | wikison+=toWikiSon("isLink",isLink); | ||
+ | wikison+=toWikiSon("type",type); | ||
+ | wikison+=toWikiSon("name",name); | ||
+ | wikison+=toWikiSon("label",label); | ||
+ | wikison+=toWikiSon("primaryKey",primaryKey); | ||
+ | wikison+=toWikiSon("namespace",namespace); | ||
+ | wikison+=toWikiSon("size",size); | ||
+ | wikison+=toWikiSon("documentation",documentation); | ||
wikison+=toWikiSon("nullable",nullable); | wikison+=toWikiSon("nullable",nullable); | ||
wikison+=toWikiSon("topic",topic); | wikison+=toWikiSon("topic",topic); | ||
wikison+="}}\n"; | wikison+="}}\n"; | ||
return wikison; | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this Property to a SiDIF string | ||
+ | * @return the SiDIF representation of this Property | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA Property\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("index",index,"Number"); | ||
+ | siDIF+=propertySiDIF("sortPos",sortPos,"Number"); | ||
+ | siDIF+=propertySiDIF("mandatory",mandatory,"Boolean"); | ||
+ | siDIF+=propertySiDIF("uploadable",uploadable,"Boolean"); | ||
+ | siDIF+=propertySiDIF("defaultValue",defaultValue,"Code"); | ||
+ | siDIF+=propertySiDIF("inputType",inputType,"Text"); | ||
+ | siDIF+=propertySiDIF("allowedValues",allowedValues,"Text"); | ||
+ | siDIF+=propertySiDIF("values_from",values_from,"Code"); | ||
+ | siDIF+=propertySiDIF("showInGrid",showInGrid,"Boolean"); | ||
+ | siDIF+=propertySiDIF("isLink",isLink,"Boolean"); | ||
+ | siDIF+=propertySiDIF("type",type,"Page"); | ||
+ | siDIF+=propertySiDIF("name",name,"Text"); | ||
+ | siDIF+=propertySiDIF("label",label,"Text"); | ||
+ | siDIF+=propertySiDIF("primaryKey",primaryKey,"Boolean"); | ||
+ | siDIF+=propertySiDIF("namespace",namespace,"Text"); | ||
+ | siDIF+=propertySiDIF("size",size,"Number"); | ||
+ | siDIF+=propertySiDIF("documentation",documentation,"Text"); | ||
+ | siDIF+=propertySiDIF("nullable",nullable,"Boolean"); | ||
+ | siDIF+=propertySiDIF("topic",topic,"Page"); | ||
+ | return siDIF; | ||
} | } | ||
Line 377: | Line 462: | ||
public Property(TripleQuery query,String pageid) { | public Property(TripleQuery query,String pageid) { | ||
this.pageid=pageid; | this.pageid=pageid; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Triple indexTriple=query.selectSingle(pageid,"index",null); | Triple indexTriple=query.selectSingle(pageid,"index",null); | ||
if (indexTriple==null) | if (indexTriple==null) | ||
Line 402: | Line 472: | ||
if (sortPosTriple!=null) | if (sortPosTriple!=null) | ||
sortPos=sortPosTriple.getObject().toString(); | sortPos=sortPosTriple.getObject().toString(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
Triple mandatoryTriple=query.selectSingle(pageid,"mandatory",null); | Triple mandatoryTriple=query.selectSingle(pageid,"mandatory",null); | ||
if (mandatoryTriple==null) | if (mandatoryTriple==null) | ||
Line 412: | Line 477: | ||
if (mandatoryTriple!=null) | if (mandatoryTriple!=null) | ||
mandatory=mandatoryTriple.getObject().toString(); | mandatory=mandatoryTriple.getObject().toString(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Triple uploadableTriple=query.selectSingle(pageid,"uploadable",null); | Triple uploadableTriple=query.selectSingle(pageid,"uploadable",null); | ||
if (uploadableTriple==null) | if (uploadableTriple==null) | ||
Line 442: | Line 497: | ||
if (allowedValuesTriple!=null) | if (allowedValuesTriple!=null) | ||
allowedValues=allowedValuesTriple.getObject().toString(); | allowedValues=allowedValuesTriple.getObject().toString(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
Triple values_fromTriple=query.selectSingle(pageid,"values_from",null); | Triple values_fromTriple=query.selectSingle(pageid,"values_from",null); | ||
if (values_fromTriple==null) | if (values_fromTriple==null) | ||
Line 462: | Line 512: | ||
if (isLinkTriple!=null) | if (isLinkTriple!=null) | ||
isLink=isLinkTriple.getObject().toString(); | isLink=isLinkTriple.getObject().toString(); | ||
+ | Triple typeTriple=query.selectSingle(pageid,"type",null); | ||
+ | if (typeTriple==null) | ||
+ | typeTriple=query.selectSingle(pageid,"Property:Property_type",null); | ||
+ | if (typeTriple!=null) | ||
+ | type=typeTriple.getObject().toString(); | ||
+ | Triple nameTriple=query.selectSingle(pageid,"name",null); | ||
+ | if (nameTriple==null) | ||
+ | nameTriple=query.selectSingle(pageid,"Property:Property_name",null); | ||
+ | if (nameTriple!=null) | ||
+ | name=nameTriple.getObject().toString(); | ||
+ | Triple labelTriple=query.selectSingle(pageid,"label",null); | ||
+ | if (labelTriple==null) | ||
+ | labelTriple=query.selectSingle(pageid,"Property:Property_label",null); | ||
+ | if (labelTriple!=null) | ||
+ | label=labelTriple.getObject().toString(); | ||
+ | Triple primaryKeyTriple=query.selectSingle(pageid,"primaryKey",null); | ||
+ | if (primaryKeyTriple==null) | ||
+ | primaryKeyTriple=query.selectSingle(pageid,"Property:Property_primaryKey",null); | ||
+ | if (primaryKeyTriple!=null) | ||
+ | primaryKey=primaryKeyTriple.getObject().toString(); | ||
+ | Triple namespaceTriple=query.selectSingle(pageid,"namespace",null); | ||
+ | if (namespaceTriple==null) | ||
+ | namespaceTriple=query.selectSingle(pageid,"Property:Property_namespace",null); | ||
+ | if (namespaceTriple!=null) | ||
+ | namespace=namespaceTriple.getObject().toString(); | ||
+ | Triple sizeTriple=query.selectSingle(pageid,"size",null); | ||
+ | if (sizeTriple==null) | ||
+ | sizeTriple=query.selectSingle(pageid,"Property:Property_size",null); | ||
+ | if (sizeTriple!=null) | ||
+ | size=sizeTriple.getObject().toString(); | ||
+ | Triple documentationTriple=query.selectSingle(pageid,"documentation",null); | ||
+ | if (documentationTriple==null) | ||
+ | documentationTriple=query.selectSingle(pageid,"Property:Property_documentation",null); | ||
+ | if (documentationTriple!=null) | ||
+ | documentation=documentationTriple.getObject().toString(); | ||
Triple nullableTriple=query.selectSingle(pageid,"nullable",null); | Triple nullableTriple=query.selectSingle(pageid,"nullable",null); | ||
if (nullableTriple==null) | if (nullableTriple==null) | ||
Line 558: | Line 643: | ||
} // class Property Manager | } // class Property Manager | ||
/** | /** | ||
− | * | + | * Context |
− | * | + | * A Context groups some topics like a Namespace/Package |
*/ | */ | ||
− | public static class | + | public static class Context extends TopicBase { |
− | public String | + | public String name; |
− | public String | + | public String since; |
− | public String | + | public String master; |
− | |||
− | |||
− | |||
− | public String | + | public String getName() { return name; } |
− | public void | + | public void setName(String pName) { name=pName; } |
− | public String | + | public String getSince() { return since; } |
− | public void | + | public void setSince(String pSince) { since=pSince; } |
− | public String | + | public String getMaster() { return master; } |
− | public void | + | public void setMaster(String pMaster) { master=pMaster; } |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
/** | /** | ||
− | * convert this | + | * convert this Context to a JSON string |
*/ | */ | ||
public String toJson() { return JSON.toJSONString(this); } | public String toJson() { return JSON.toJSONString(this); } | ||
/** | /** | ||
− | * convert this | + | * convert this Context to a WikiSon string |
+ | * @return the WikiSon representation of this Context | ||
*/ | */ | ||
public String toWikiSon() { | public String toWikiSon() { | ||
− | String wikison= "{{ | + | String wikison= "{{Context\n"; |
− | wikison+=toWikiSon(" | + | wikison+=toWikiSon("name",name); |
− | wikison+=toWikiSon(" | + | wikison+=toWikiSon("since",since); |
− | wikison+=toWikiSon(" | + | wikison+=toWikiSon("master",master); |
− | |||
− | |||
− | |||
wikison+="}}\n"; | wikison+="}}\n"; | ||
return wikison; | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this Context to a SiDIF string | ||
+ | * @return the SiDIF representation of this Context | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA Context\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("name",name,"Text"); | ||
+ | siDIF+=propertySiDIF("since",since,"Date"); | ||
+ | siDIF+=propertySiDIF("master",master,"URL"); | ||
+ | return siDIF; | ||
} | } | ||
Line 608: | Line 694: | ||
/** | /** | ||
− | * default constructor for | + | * default constructor for Context |
*/ | */ | ||
− | public | + | public Context() {} |
/** | /** | ||
− | * construct a | + | * construct a Context from the given Triple |
* @param query - the TripleQuery to get the triples from | * @param query - the TripleQuery to get the triples from | ||
− | * @param | + | * @param pContextTriple - the triple to construct me from |
*/ | */ | ||
− | public | + | public Context(TripleQuery query,Triple pContextTriple) { |
− | this(query, | + | this(query,pContextTriple.getSubject().toString()); |
} // constructor | } // constructor | ||
/** | /** | ||
− | * construct a | + | * construct a Context from the given pageId |
* @param query - the TripleQuery to get the triples from | * @param query - the TripleQuery to get the triples from | ||
* @param pageid - pageid | * @param pageid - pageid | ||
*/ | */ | ||
− | public | + | public Context(TripleQuery query,String pageid) { |
this.pageid=pageid; | this.pageid=pageid; | ||
− | Triple | + | Triple nameTriple=query.selectSingle(pageid,"name",null); |
− | if ( | + | if (nameTriple==null) |
− | + | nameTriple=query.selectSingle(pageid,"Property:Context_name",null); | |
− | if ( | + | if (nameTriple!=null) |
− | + | name=nameTriple.getObject().toString(); | |
− | Triple | + | Triple sinceTriple=query.selectSingle(pageid,"since",null); |
− | if ( | + | if (sinceTriple==null) |
− | + | sinceTriple=query.selectSingle(pageid,"Property:Context_since",null); | |
− | if ( | + | if (sinceTriple!=null) |
− | + | since=sinceTriple.getObject().toString(); | |
− | Triple | + | Triple masterTriple=query.selectSingle(pageid,"master",null); |
− | if ( | + | if (masterTriple==null) |
− | + | masterTriple=query.selectSingle(pageid,"Property:Context_master",null); | |
− | if ( | + | if (masterTriple!=null) |
− | + | master=masterTriple.getObject().toString(); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
init(query); | init(query); | ||
− | } // constructor for | + | } // constructor for Context |
− | // >>>{user defined topic code}{ | + | // >>>{user defined topic code}{Context}{Context} |
− | // <<<{user defined topic code}{ | + | // <<<{user defined topic code}{Context}{Context} |
− | } // class | + | } // class Context |
/** | /** | ||
− | * Manager for | + | * Manager for Context |
*/ | */ | ||
− | public static class | + | public static class ContextManager extends TopicBase { |
− | public String topicName=" | + | public String topicName="Context"; |
− | public transient List< | + | public transient List<Context> mContexts=new ArrayList<Context>(); |
− | public transient Map<String, | + | public transient Map<String,Context> mContextMap=new LinkedHashMap<String,Context>(); |
/** | /** | ||
− | * get my | + | * get my Contexts |
*/ | */ | ||
− | public List< | + | public List<Context> getContexts() { |
− | List< | + | List<Context> result=this.mContexts; |
return result; | return result; | ||
} | } | ||
/** | /** | ||
− | * add a new | + | * add a new Context |
*/ | */ | ||
− | public | + | public Context add(Context pContext) { |
− | + | mContexts.add(pContext); | |
− | + | mContextMap.put(pContext.getPageid(),pContext); | |
− | return | + | return pContext; |
} | } | ||
/** | /** | ||
− | * add a new | + | * add a new Context from the given triple |
*/ | */ | ||
− | public | + | public Context add(TripleQuery query,Triple pContextTriple) { |
− | + | Context lContext=new Context(query,pContextTriple); | |
− | add( | + | add(lContext); |
− | return | + | return lContext; |
} | } | ||
− | // reinitialize my | + | // reinitialize my mContext map |
public void reinit() { | public void reinit() { | ||
− | + | mContextMap.clear(); | |
− | for ( | + | for (Context lContext:mContexts) { |
− | + | mContextMap.put(lContext.getPageid(),lContext); | |
} | } | ||
} | } | ||
Line 711: | Line 782: | ||
// get a new manager from the given json string | // get a new manager from the given json string | ||
− | public static | + | public static ContextManager fromJson(String json) { |
− | + | ContextManager result=JSON.parseObject(json, ContextManager.class); | |
result.reinit(); | result.reinit(); | ||
return result; | return result; | ||
} | } | ||
− | // default constructor for | + | // default constructor for Context Manager |
− | public | + | public ContextManager() {} |
− | // add | + | // add Contexts from the given query |
− | public void | + | public void addContexts(TripleQuery pContextQuery,TripleQuery query) { |
− | if ( | + | if (pContextQuery!=null) { |
− | for (Triple | + | for (Triple lContextTriple:pContextQuery.getTriples()) { |
− | add(query, | + | add(query,lContextTriple); |
} | } | ||
} | } | ||
Line 730: | Line 801: | ||
// construct me from the given triple Query query | // construct me from the given triple Query query | ||
− | public | + | public ContextManager(TripleQuery query) { |
// first query the SiDIF bases triplestore | // first query the SiDIF bases triplestore | ||
− | TripleQuery | + | TripleQuery lContextQuery=query.query(null,"isA","Context"); |
− | + | addContexts(lContextQuery,query); | |
// then the SMW triplestore | // then the SMW triplestore | ||
− | + | lContextQuery=query.query(null,"Property:IsA","Context"); | |
− | + | addContexts(lContextQuery,query); | |
init(query); | init(query); | ||
− | } // constructor for | + | } // constructor for Context Manager |
− | // >>>{user defined topicmanager code}{ | + | // >>>{user defined topicmanager code}{Context}{Context} |
− | // <<<{user defined topicmanager code}{ | + | // <<<{user defined topicmanager code}{Context}{Context} |
− | } // class | + | } // class Context Manager |
/** | /** | ||
* Topic | * Topic | ||
Line 749: | Line 820: | ||
public static class Topic extends TopicBase { | public static class Topic extends TopicBase { | ||
+ | public String pluralName; | ||
+ | public String documentation; | ||
+ | public String cargo; | ||
public String name; | public String name; | ||
− | |||
public String icon; | public String icon; | ||
public String iconUrl; | public String iconUrl; | ||
− | |||
public String wikiDocumentation; | public String wikiDocumentation; | ||
public String defaultstoremode; | public String defaultstoremode; | ||
public String listLimit; | public String listLimit; | ||
− | |||
public String headerTabs; | public String headerTabs; | ||
public String context; | public String context; | ||
+ | public String getPluralName() { return pluralName; } | ||
+ | public void setPluralName(String pPluralName) { pluralName=pPluralName; } | ||
+ | public String getDocumentation() { return documentation; } | ||
+ | public void setDocumentation(String pDocumentation) { documentation=pDocumentation; } | ||
+ | public String getCargo() { return cargo; } | ||
+ | public void setCargo(String pCargo) { cargo=pCargo; } | ||
public String getName() { return name; } | public String getName() { return name; } | ||
public void setName(String pName) { name=pName; } | public void setName(String pName) { name=pName; } | ||
− | |||
− | |||
public String getIcon() { return icon; } | public String getIcon() { return icon; } | ||
public void setIcon(String pIcon) { icon=pIcon; } | public void setIcon(String pIcon) { icon=pIcon; } | ||
public String getIconUrl() { return iconUrl; } | public String getIconUrl() { return iconUrl; } | ||
public void setIconUrl(String pIconUrl) { iconUrl=pIconUrl; } | public void setIconUrl(String pIconUrl) { iconUrl=pIconUrl; } | ||
− | |||
− | |||
public String getWikiDocumentation() { return wikiDocumentation; } | public String getWikiDocumentation() { return wikiDocumentation; } | ||
public void setWikiDocumentation(String pWikiDocumentation) { wikiDocumentation=pWikiDocumentation; } | public void setWikiDocumentation(String pWikiDocumentation) { wikiDocumentation=pWikiDocumentation; } | ||
Line 777: | Line 850: | ||
public String getListLimit() { return listLimit; } | public String getListLimit() { return listLimit; } | ||
public void setListLimit(String pListLimit) { listLimit=pListLimit; } | public void setListLimit(String pListLimit) { listLimit=pListLimit; } | ||
− | |||
− | |||
public String getHeaderTabs() { return headerTabs; } | public String getHeaderTabs() { return headerTabs; } | ||
public void setHeaderTabs(String pHeaderTabs) { headerTabs=pHeaderTabs; } | public void setHeaderTabs(String pHeaderTabs) { headerTabs=pHeaderTabs; } | ||
Line 790: | Line 861: | ||
/** | /** | ||
* convert this Topic to a WikiSon string | * convert this Topic to a WikiSon string | ||
+ | * @return the WikiSon representation of this Topic | ||
*/ | */ | ||
public String toWikiSon() { | public String toWikiSon() { | ||
String wikison= "{{Topic\n"; | String wikison= "{{Topic\n"; | ||
+ | wikison+=toWikiSon("pluralName",pluralName); | ||
+ | wikison+=toWikiSon("documentation",documentation); | ||
+ | wikison+=toWikiSon("cargo",cargo); | ||
wikison+=toWikiSon("name",name); | wikison+=toWikiSon("name",name); | ||
− | |||
wikison+=toWikiSon("icon",icon); | wikison+=toWikiSon("icon",icon); | ||
wikison+=toWikiSon("iconUrl",iconUrl); | wikison+=toWikiSon("iconUrl",iconUrl); | ||
− | |||
wikison+=toWikiSon("wikiDocumentation",wikiDocumentation); | wikison+=toWikiSon("wikiDocumentation",wikiDocumentation); | ||
wikison+=toWikiSon("defaultstoremode",defaultstoremode); | wikison+=toWikiSon("defaultstoremode",defaultstoremode); | ||
wikison+=toWikiSon("listLimit",listLimit); | wikison+=toWikiSon("listLimit",listLimit); | ||
− | |||
wikison+=toWikiSon("headerTabs",headerTabs); | wikison+=toWikiSon("headerTabs",headerTabs); | ||
wikison+=toWikiSon("context",context); | wikison+=toWikiSon("context",context); | ||
wikison+="}}\n"; | wikison+="}}\n"; | ||
return wikison; | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this Topic to a SiDIF string | ||
+ | * @return the SiDIF representation of this Topic | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA Topic\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("pluralName",pluralName,"Text"); | ||
+ | siDIF+=propertySiDIF("documentation",documentation,"Text"); | ||
+ | siDIF+=propertySiDIF("cargo",cargo,"Boolean"); | ||
+ | siDIF+=propertySiDIF("name",name,"Text"); | ||
+ | siDIF+=propertySiDIF("icon",icon,"Page"); | ||
+ | siDIF+=propertySiDIF("iconUrl",iconUrl,"Code"); | ||
+ | siDIF+=propertySiDIF("wikiDocumentation",wikiDocumentation,"Text"); | ||
+ | siDIF+=propertySiDIF("defaultstoremode",defaultstoremode,"Text"); | ||
+ | siDIF+=propertySiDIF("listLimit",listLimit,"Number"); | ||
+ | siDIF+=propertySiDIF("headerTabs",headerTabs,"Boolean"); | ||
+ | siDIF+=propertySiDIF("context",context,"Page"); | ||
+ | return siDIF; | ||
} | } | ||
Line 834: | Line 926: | ||
public Topic(TripleQuery query,String pageid) { | public Topic(TripleQuery query,String pageid) { | ||
this.pageid=pageid; | this.pageid=pageid; | ||
+ | Triple pluralNameTriple=query.selectSingle(pageid,"pluralName",null); | ||
+ | if (pluralNameTriple==null) | ||
+ | pluralNameTriple=query.selectSingle(pageid,"Property:Topic_pluralName",null); | ||
+ | if (pluralNameTriple!=null) | ||
+ | pluralName=pluralNameTriple.getObject().toString(); | ||
+ | Triple documentationTriple=query.selectSingle(pageid,"documentation",null); | ||
+ | if (documentationTriple==null) | ||
+ | documentationTriple=query.selectSingle(pageid,"Property:Topic_documentation",null); | ||
+ | if (documentationTriple!=null) | ||
+ | documentation=documentationTriple.getObject().toString(); | ||
+ | Triple cargoTriple=query.selectSingle(pageid,"cargo",null); | ||
+ | if (cargoTriple==null) | ||
+ | cargoTriple=query.selectSingle(pageid,"Property:Topic_cargo",null); | ||
+ | if (cargoTriple!=null) | ||
+ | cargo=cargoTriple.getObject().toString(); | ||
Triple nameTriple=query.selectSingle(pageid,"name",null); | Triple nameTriple=query.selectSingle(pageid,"name",null); | ||
if (nameTriple==null) | if (nameTriple==null) | ||
Line 839: | Line 946: | ||
if (nameTriple!=null) | if (nameTriple!=null) | ||
name=nameTriple.getObject().toString(); | name=nameTriple.getObject().toString(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
Triple iconTriple=query.selectSingle(pageid,"icon",null); | Triple iconTriple=query.selectSingle(pageid,"icon",null); | ||
if (iconTriple==null) | if (iconTriple==null) | ||
Line 854: | Line 956: | ||
if (iconUrlTriple!=null) | if (iconUrlTriple!=null) | ||
iconUrl=iconUrlTriple.getObject().toString(); | iconUrl=iconUrlTriple.getObject().toString(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
Triple wikiDocumentationTriple=query.selectSingle(pageid,"wikiDocumentation",null); | Triple wikiDocumentationTriple=query.selectSingle(pageid,"wikiDocumentation",null); | ||
if (wikiDocumentationTriple==null) | if (wikiDocumentationTriple==null) | ||
Line 874: | Line 971: | ||
if (listLimitTriple!=null) | if (listLimitTriple!=null) | ||
listLimit=listLimitTriple.getObject().toString(); | listLimit=listLimitTriple.getObject().toString(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
Triple headerTabsTriple=query.selectSingle(pageid,"headerTabs",null); | Triple headerTabsTriple=query.selectSingle(pageid,"headerTabs",null); | ||
if (headerTabsTriple==null) | if (headerTabsTriple==null) | ||
Line 1,021: | Line 1,113: | ||
/** | /** | ||
* convert this Action to a WikiSon string | * convert this Action to a WikiSon string | ||
+ | * @return the WikiSon representation of this Action | ||
*/ | */ | ||
public String toWikiSon() { | public String toWikiSon() { | ||
Line 1,037: | Line 1,130: | ||
wikison+="}}\n"; | wikison+="}}\n"; | ||
return wikison; | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this Action to a SiDIF string | ||
+ | * @return the SiDIF representation of this Action | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA Action\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("name",name,"Text"); | ||
+ | siDIF+=propertySiDIF("servicetype",servicetype,"Text"); | ||
+ | siDIF+=propertySiDIF("service",service,"URL"); | ||
+ | siDIF+=propertySiDIF("inputtype",inputtype,"Text"); | ||
+ | siDIF+=propertySiDIF("input",input,"Code"); | ||
+ | siDIF+=propertySiDIF("actionpage",actionpage,"Page"); | ||
+ | siDIF+=propertySiDIF("output",output,"Text"); | ||
+ | siDIF+=propertySiDIF("engine",engine,"Text"); | ||
+ | siDIF+=propertySiDIF("author",author,"Page"); | ||
+ | siDIF+=propertySiDIF("since",since,"Date"); | ||
+ | siDIF+=propertySiDIF("comment",comment,"Text"); | ||
+ | return siDIF; | ||
} | } | ||
Line 1,211: | Line 1,324: | ||
public static class TopicLink extends TopicBase { | public static class TopicLink extends TopicBase { | ||
+ | public String masterDetail; | ||
public String name; | public String name; | ||
public String source; | public String source; | ||
Line 1,220: | Line 1,334: | ||
public String targetMultiple; | public String targetMultiple; | ||
public String targetDocumentation; | public String targetDocumentation; | ||
− | |||
+ | public String getMasterDetail() { return masterDetail; } | ||
+ | public void setMasterDetail(String pMasterDetail) { masterDetail=pMasterDetail; } | ||
public String getName() { return name; } | public String getName() { return name; } | ||
public void setName(String pName) { name=pName; } | public void setName(String pName) { name=pName; } | ||
Line 1,240: | Line 1,355: | ||
public String getTargetDocumentation() { return targetDocumentation; } | public String getTargetDocumentation() { return targetDocumentation; } | ||
public void setTargetDocumentation(String pTargetDocumentation) { targetDocumentation=pTargetDocumentation; } | public void setTargetDocumentation(String pTargetDocumentation) { targetDocumentation=pTargetDocumentation; } | ||
− | |||
− | |||
/** | /** | ||
* convert this TopicLink to a JSON string | * convert this TopicLink to a JSON string | ||
Line 1,249: | Line 1,362: | ||
/** | /** | ||
* convert this TopicLink to a WikiSon string | * convert this TopicLink to a WikiSon string | ||
+ | * @return the WikiSon representation of this TopicLink | ||
*/ | */ | ||
public String toWikiSon() { | public String toWikiSon() { | ||
String wikison= "{{TopicLink\n"; | String wikison= "{{TopicLink\n"; | ||
+ | wikison+=toWikiSon("masterDetail",masterDetail); | ||
wikison+=toWikiSon("name",name); | wikison+=toWikiSon("name",name); | ||
wikison+=toWikiSon("source",source); | wikison+=toWikiSon("source",source); | ||
Line 1,261: | Line 1,376: | ||
wikison+=toWikiSon("targetMultiple",targetMultiple); | wikison+=toWikiSon("targetMultiple",targetMultiple); | ||
wikison+=toWikiSon("targetDocumentation",targetDocumentation); | wikison+=toWikiSon("targetDocumentation",targetDocumentation); | ||
− | |||
wikison+="}}\n"; | wikison+="}}\n"; | ||
return wikison; | return wikison; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * convert this TopicLink to a SiDIF string | ||
+ | * @return the SiDIF representation of this TopicLink | ||
+ | */ | ||
+ | public String toSiDIF() { | ||
+ | String siDIF = String.format("%s isA TopicLink\n",this.pageid); | ||
+ | siDIF+=propertySiDIF("masterDetail",masterDetail,"Boolean"); | ||
+ | siDIF+=propertySiDIF("name",name,"Text"); | ||
+ | siDIF+=propertySiDIF("source",source,"Page"); | ||
+ | siDIF+=propertySiDIF("sourceRole",sourceRole,"Text"); | ||
+ | siDIF+=propertySiDIF("sourceMultiple",sourceMultiple,"Boolean"); | ||
+ | siDIF+=propertySiDIF("sourceDocumentation",sourceDocumentation,"Text"); | ||
+ | siDIF+=propertySiDIF("target",target,"Page"); | ||
+ | siDIF+=propertySiDIF("targetRole",targetRole,"Text"); | ||
+ | siDIF+=propertySiDIF("targetMultiple",targetMultiple,"Boolean"); | ||
+ | siDIF+=propertySiDIF("targetDocumentation",targetDocumentation,"Text"); | ||
+ | return siDIF; | ||
} | } | ||
Line 1,292: | Line 1,425: | ||
public TopicLink(TripleQuery query,String pageid) { | public TopicLink(TripleQuery query,String pageid) { | ||
this.pageid=pageid; | this.pageid=pageid; | ||
+ | Triple masterDetailTriple=query.selectSingle(pageid,"masterDetail",null); | ||
+ | if (masterDetailTriple==null) | ||
+ | masterDetailTriple=query.selectSingle(pageid,"Property:TopicLink_masterDetail",null); | ||
+ | if (masterDetailTriple!=null) | ||
+ | masterDetail=masterDetailTriple.getObject().toString(); | ||
Triple nameTriple=query.selectSingle(pageid,"name",null); | Triple nameTriple=query.selectSingle(pageid,"name",null); | ||
if (nameTriple==null) | if (nameTriple==null) | ||
Line 1,337: | Line 1,475: | ||
if (targetDocumentationTriple!=null) | if (targetDocumentationTriple!=null) | ||
targetDocumentation=targetDocumentationTriple.getObject().toString(); | targetDocumentation=targetDocumentationTriple.getObject().toString(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
init(query); | init(query); | ||
} // constructor for TopicLink | } // constructor for TopicLink | ||
Line 1,429: | Line 1,562: | ||
} | } | ||
+ | </source> |
Latest revision as of 05:57, 11 October 2019
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
*/
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
/**
* SMW_Type
* an SMW_Type is a data type which determines the possible values for that type e.g. a Boolean can hold true/false values while a Number can hold 3.1459 or 20. A Page can hold the name of a Wiki page see https://semantic-mediawiki.org/wiki/Help:List_of_datatypes
*/
public static class SMW_Type extends TopicBase {
public String type;
public String typepage;
public String usedByProperties;
public String documentation;
public String helppage;
public String javaType;
public String id;
public String getType() { return type; }
public void setType(String pType) { type=pType; }
public String getTypepage() { return typepage; }
public void setTypepage(String pTypepage) { typepage=pTypepage; }
public String getUsedByProperties() { return usedByProperties; }
public void setUsedByProperties(String pUsedByProperties) { usedByProperties=pUsedByProperties; }
public String getDocumentation() { return documentation; }
public void setDocumentation(String pDocumentation) { documentation=pDocumentation; }
public String getHelppage() { return helppage; }
public void setHelppage(String pHelppage) { helppage=pHelppage; }
public String getJavaType() { return javaType; }
public void setJavaType(String pJavaType) { javaType=pJavaType; }
public String getId() { return id; }
public void setId(String pId) { id=pId; }
/**
* convert this SMW_Type to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this SMW_Type to a WikiSon string
* @return the WikiSon representation of this SMW_Type
*/
public String toWikiSon() {
String wikison= "{{SMW_Type\n";
wikison+=toWikiSon("type",type);
wikison+=toWikiSon("typepage",typepage);
wikison+=toWikiSon("usedByProperties",usedByProperties);
wikison+=toWikiSon("documentation",documentation);
wikison+=toWikiSon("helppage",helppage);
wikison+=toWikiSon("javaType",javaType);
wikison+=toWikiSon("id",id);
wikison+="}}\n";
return wikison;
}
/**
* convert this SMW_Type to a SiDIF string
* @return the SiDIF representation of this SMW_Type
*/
public String toSiDIF() {
String siDIF = String.format("%s isA SMW_Type\n",this.pageid);
siDIF+=propertySiDIF("type",type,"Text");
siDIF+=propertySiDIF("typepage",typepage,"Page");
siDIF+=propertySiDIF("usedByProperties",usedByProperties,"Page");
siDIF+=propertySiDIF("documentation",documentation,"Text");
siDIF+=propertySiDIF("helppage",helppage,"URL");
siDIF+=propertySiDIF("javaType",javaType,"Text");
siDIF+=propertySiDIF("id",id,"Text");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for SMW_Type
*/
public SMW_Type() {}
/**
* construct a SMW_Type from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pSMW_TypeTriple - the triple to construct me from
*/
public SMW_Type(TripleQuery query,Triple pSMW_TypeTriple) {
this(query,pSMW_TypeTriple.getSubject().toString());
} // constructor
/**
* construct a SMW_Type from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public SMW_Type(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple typeTriple=query.selectSingle(pageid,"type",null);
if (typeTriple==null)
typeTriple=query.selectSingle(pageid,"Property:SMW_Type_type",null);
if (typeTriple!=null)
type=typeTriple.getObject().toString();
Triple typepageTriple=query.selectSingle(pageid,"typepage",null);
if (typepageTriple==null)
typepageTriple=query.selectSingle(pageid,"Property:SMW_Type_typepage",null);
if (typepageTriple!=null)
typepage=typepageTriple.getObject().toString();
Triple usedByPropertiesTriple=query.selectSingle(pageid,"usedByProperties",null);
if (usedByPropertiesTriple==null)
usedByPropertiesTriple=query.selectSingle(pageid,"Property:SMW_Type_usedByProperties",null);
if (usedByPropertiesTriple!=null)
usedByProperties=usedByPropertiesTriple.getObject().toString();
Triple documentationTriple=query.selectSingle(pageid,"documentation",null);
if (documentationTriple==null)
documentationTriple=query.selectSingle(pageid,"Property:SMW_Type_documentation",null);
if (documentationTriple!=null)
documentation=documentationTriple.getObject().toString();
Triple helppageTriple=query.selectSingle(pageid,"helppage",null);
if (helppageTriple==null)
helppageTriple=query.selectSingle(pageid,"Property:SMW_Type_helppage",null);
if (helppageTriple!=null)
helppage=helppageTriple.getObject().toString();
Triple javaTypeTriple=query.selectSingle(pageid,"javaType",null);
if (javaTypeTriple==null)
javaTypeTriple=query.selectSingle(pageid,"Property:SMW_Type_javaType",null);
if (javaTypeTriple!=null)
javaType=javaTypeTriple.getObject().toString();
Triple idTriple=query.selectSingle(pageid,"id",null);
if (idTriple==null)
idTriple=query.selectSingle(pageid,"Property:SMW_Type_id",null);
if (idTriple!=null)
id=idTriple.getObject().toString();
init(query);
} // constructor for SMW_Type
// >>>{user defined topic code}{SMW_Type}{SMW_Type}
// <<<{user defined topic code}{SMW_Type}{SMW_Type}
} // class SMW_Type
/**
* Manager for SMW_Type
*/
public static class SMW_TypeManager extends TopicBase {
public String topicName="SMW_Type";
public transient List<SMW_Type> mSMW_Types=new ArrayList<SMW_Type>();
public transient Map<String,SMW_Type> mSMW_TypeMap=new LinkedHashMap<String,SMW_Type>();
/**
* get my SMW_Types
*/
public List<SMW_Type> getSMW_Types() {
List<SMW_Type> result=this.mSMW_Types;
return result;
}
/**
* add a new SMW_Type
*/
public SMW_Type add(SMW_Type pSMW_Type) {
mSMW_Types.add(pSMW_Type);
mSMW_TypeMap.put(pSMW_Type.getPageid(),pSMW_Type);
return pSMW_Type;
}
/**
* add a new SMW_Type from the given triple
*/
public SMW_Type add(TripleQuery query,Triple pSMW_TypeTriple) {
SMW_Type lSMW_Type=new SMW_Type(query,pSMW_TypeTriple);
add(lSMW_Type);
return lSMW_Type;
}
// reinitialize my mSMW_Type map
public void reinit() {
mSMW_TypeMap.clear();
for (SMW_Type lSMW_Type:mSMW_Types) {
mSMW_TypeMap.put(lSMW_Type.getPageid(),lSMW_Type);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static SMW_TypeManager fromJson(String json) {
SMW_TypeManager result=JSON.parseObject(json, SMW_TypeManager.class);
result.reinit();
return result;
}
// default constructor for SMW_Type Manager
public SMW_TypeManager() {}
// add SMW_Types from the given query
public void addSMW_Types(TripleQuery pSMW_TypeQuery,TripleQuery query) {
if (pSMW_TypeQuery!=null) {
for (Triple lSMW_TypeTriple:pSMW_TypeQuery.getTriples()) {
add(query,lSMW_TypeTriple);
}
}
}
// construct me from the given triple Query query
public SMW_TypeManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lSMW_TypeQuery=query.query(null,"isA","SMW_Type");
addSMW_Types(lSMW_TypeQuery,query);
// then the SMW triplestore
lSMW_TypeQuery=query.query(null,"Property:IsA","SMW_Type");
addSMW_Types(lSMW_TypeQuery,query);
init(query);
} // constructor for SMW_Type Manager
// >>>{user defined topicmanager code}{SMW_Type}{SMW_Type}
// <<<{user defined topicmanager code}{SMW_Type}{SMW_Type}
} // class SMW_Type Manager
/**
* Property
* a Property is a Feature/Attribute of a Topic
*/
public static class Property extends TopicBase {
public String index;
public String sortPos;
public String mandatory;
public String uploadable;
public String defaultValue;
public String inputType;
public String allowedValues;
public String values_from;
public String showInGrid;
public String isLink;
public String type;
public String name;
public String label;
public String primaryKey;
public String namespace;
public String size;
public String documentation;
public String nullable;
public String topic;
public String getIndex() { return index; }
public void setIndex(String pIndex) { index=pIndex; }
public String getSortPos() { return sortPos; }
public void setSortPos(String pSortPos) { sortPos=pSortPos; }
public String getMandatory() { return mandatory; }
public void setMandatory(String pMandatory) { mandatory=pMandatory; }
public String getUploadable() { return uploadable; }
public void setUploadable(String pUploadable) { uploadable=pUploadable; }
public String getDefaultValue() { return defaultValue; }
public void setDefaultValue(String pDefaultValue) { defaultValue=pDefaultValue; }
public String getInputType() { return inputType; }
public void setInputType(String pInputType) { inputType=pInputType; }
public String getAllowedValues() { return allowedValues; }
public void setAllowedValues(String pAllowedValues) { allowedValues=pAllowedValues; }
public String getValues_from() { return values_from; }
public void setValues_from(String pValues_from) { values_from=pValues_from; }
public String getShowInGrid() { return showInGrid; }
public void setShowInGrid(String pShowInGrid) { showInGrid=pShowInGrid; }
public String getIsLink() { return isLink; }
public void setIsLink(String pIsLink) { isLink=pIsLink; }
public String getType() { return type; }
public void setType(String pType) { type=pType; }
public String getName() { return name; }
public void setName(String pName) { name=pName; }
public String getLabel() { return label; }
public void setLabel(String pLabel) { label=pLabel; }
public String getPrimaryKey() { return primaryKey; }
public void setPrimaryKey(String pPrimaryKey) { primaryKey=pPrimaryKey; }
public String getNamespace() { return namespace; }
public void setNamespace(String pNamespace) { namespace=pNamespace; }
public String getSize() { return size; }
public void setSize(String pSize) { size=pSize; }
public String getDocumentation() { return documentation; }
public void setDocumentation(String pDocumentation) { documentation=pDocumentation; }
public String getNullable() { return nullable; }
public void setNullable(String pNullable) { nullable=pNullable; }
public String getTopic() { return topic; }
public void setTopic(String pTopic) { topic=pTopic; }
/**
* convert this Property to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Property to a WikiSon string
* @return the WikiSon representation of this Property
*/
public String toWikiSon() {
String wikison= "{{Property\n";
wikison+=toWikiSon("index",index);
wikison+=toWikiSon("sortPos",sortPos);
wikison+=toWikiSon("mandatory",mandatory);
wikison+=toWikiSon("uploadable",uploadable);
wikison+=toWikiSon("defaultValue",defaultValue);
wikison+=toWikiSon("inputType",inputType);
wikison+=toWikiSon("allowedValues",allowedValues);
wikison+=toWikiSon("values_from",values_from);
wikison+=toWikiSon("showInGrid",showInGrid);
wikison+=toWikiSon("isLink",isLink);
wikison+=toWikiSon("type",type);
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("label",label);
wikison+=toWikiSon("primaryKey",primaryKey);
wikison+=toWikiSon("namespace",namespace);
wikison+=toWikiSon("size",size);
wikison+=toWikiSon("documentation",documentation);
wikison+=toWikiSon("nullable",nullable);
wikison+=toWikiSon("topic",topic);
wikison+="}}\n";
return wikison;
}
/**
* convert this Property to a SiDIF string
* @return the SiDIF representation of this Property
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Property\n",this.pageid);
siDIF+=propertySiDIF("index",index,"Number");
siDIF+=propertySiDIF("sortPos",sortPos,"Number");
siDIF+=propertySiDIF("mandatory",mandatory,"Boolean");
siDIF+=propertySiDIF("uploadable",uploadable,"Boolean");
siDIF+=propertySiDIF("defaultValue",defaultValue,"Code");
siDIF+=propertySiDIF("inputType",inputType,"Text");
siDIF+=propertySiDIF("allowedValues",allowedValues,"Text");
siDIF+=propertySiDIF("values_from",values_from,"Code");
siDIF+=propertySiDIF("showInGrid",showInGrid,"Boolean");
siDIF+=propertySiDIF("isLink",isLink,"Boolean");
siDIF+=propertySiDIF("type",type,"Page");
siDIF+=propertySiDIF("name",name,"Text");
siDIF+=propertySiDIF("label",label,"Text");
siDIF+=propertySiDIF("primaryKey",primaryKey,"Boolean");
siDIF+=propertySiDIF("namespace",namespace,"Text");
siDIF+=propertySiDIF("size",size,"Number");
siDIF+=propertySiDIF("documentation",documentation,"Text");
siDIF+=propertySiDIF("nullable",nullable,"Boolean");
siDIF+=propertySiDIF("topic",topic,"Page");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Property
*/
public Property() {}
/**
* construct a Property from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pPropertyTriple - the triple to construct me from
*/
public Property(TripleQuery query,Triple pPropertyTriple) {
this(query,pPropertyTriple.getSubject().toString());
} // constructor
/**
* construct a Property from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Property(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple indexTriple=query.selectSingle(pageid,"index",null);
if (indexTriple==null)
indexTriple=query.selectSingle(pageid,"Property:Property_index",null);
if (indexTriple!=null)
index=indexTriple.getObject().toString();
Triple sortPosTriple=query.selectSingle(pageid,"sortPos",null);
if (sortPosTriple==null)
sortPosTriple=query.selectSingle(pageid,"Property:Property_sortPos",null);
if (sortPosTriple!=null)
sortPos=sortPosTriple.getObject().toString();
Triple mandatoryTriple=query.selectSingle(pageid,"mandatory",null);
if (mandatoryTriple==null)
mandatoryTriple=query.selectSingle(pageid,"Property:Property_mandatory",null);
if (mandatoryTriple!=null)
mandatory=mandatoryTriple.getObject().toString();
Triple uploadableTriple=query.selectSingle(pageid,"uploadable",null);
if (uploadableTriple==null)
uploadableTriple=query.selectSingle(pageid,"Property:Property_uploadable",null);
if (uploadableTriple!=null)
uploadable=uploadableTriple.getObject().toString();
Triple defaultValueTriple=query.selectSingle(pageid,"defaultValue",null);
if (defaultValueTriple==null)
defaultValueTriple=query.selectSingle(pageid,"Property:Property_defaultValue",null);
if (defaultValueTriple!=null)
defaultValue=defaultValueTriple.getObject().toString();
Triple inputTypeTriple=query.selectSingle(pageid,"inputType",null);
if (inputTypeTriple==null)
inputTypeTriple=query.selectSingle(pageid,"Property:Property_inputType",null);
if (inputTypeTriple!=null)
inputType=inputTypeTriple.getObject().toString();
Triple allowedValuesTriple=query.selectSingle(pageid,"allowedValues",null);
if (allowedValuesTriple==null)
allowedValuesTriple=query.selectSingle(pageid,"Property:Property_allowedValues",null);
if (allowedValuesTriple!=null)
allowedValues=allowedValuesTriple.getObject().toString();
Triple values_fromTriple=query.selectSingle(pageid,"values_from",null);
if (values_fromTriple==null)
values_fromTriple=query.selectSingle(pageid,"Property:Property_values_from",null);
if (values_fromTriple!=null)
values_from=values_fromTriple.getObject().toString();
Triple showInGridTriple=query.selectSingle(pageid,"showInGrid",null);
if (showInGridTriple==null)
showInGridTriple=query.selectSingle(pageid,"Property:Property_showInGrid",null);
if (showInGridTriple!=null)
showInGrid=showInGridTriple.getObject().toString();
Triple isLinkTriple=query.selectSingle(pageid,"isLink",null);
if (isLinkTriple==null)
isLinkTriple=query.selectSingle(pageid,"Property:Property_isLink",null);
if (isLinkTriple!=null)
isLink=isLinkTriple.getObject().toString();
Triple typeTriple=query.selectSingle(pageid,"type",null);
if (typeTriple==null)
typeTriple=query.selectSingle(pageid,"Property:Property_type",null);
if (typeTriple!=null)
type=typeTriple.getObject().toString();
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:Property_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple labelTriple=query.selectSingle(pageid,"label",null);
if (labelTriple==null)
labelTriple=query.selectSingle(pageid,"Property:Property_label",null);
if (labelTriple!=null)
label=labelTriple.getObject().toString();
Triple primaryKeyTriple=query.selectSingle(pageid,"primaryKey",null);
if (primaryKeyTriple==null)
primaryKeyTriple=query.selectSingle(pageid,"Property:Property_primaryKey",null);
if (primaryKeyTriple!=null)
primaryKey=primaryKeyTriple.getObject().toString();
Triple namespaceTriple=query.selectSingle(pageid,"namespace",null);
if (namespaceTriple==null)
namespaceTriple=query.selectSingle(pageid,"Property:Property_namespace",null);
if (namespaceTriple!=null)
namespace=namespaceTriple.getObject().toString();
Triple sizeTriple=query.selectSingle(pageid,"size",null);
if (sizeTriple==null)
sizeTriple=query.selectSingle(pageid,"Property:Property_size",null);
if (sizeTriple!=null)
size=sizeTriple.getObject().toString();
Triple documentationTriple=query.selectSingle(pageid,"documentation",null);
if (documentationTriple==null)
documentationTriple=query.selectSingle(pageid,"Property:Property_documentation",null);
if (documentationTriple!=null)
documentation=documentationTriple.getObject().toString();
Triple nullableTriple=query.selectSingle(pageid,"nullable",null);
if (nullableTriple==null)
nullableTriple=query.selectSingle(pageid,"Property:Property_nullable",null);
if (nullableTriple!=null)
nullable=nullableTriple.getObject().toString();
Triple topicTriple=query.selectSingle(pageid,"topic",null);
if (topicTriple==null)
topicTriple=query.selectSingle(pageid,"Property:Property_topic",null);
if (topicTriple!=null)
topic=topicTriple.getObject().toString();
init(query);
} // constructor for Property
// >>>{user defined topic code}{Property}{Property}
// <<<{user defined topic code}{Property}{Property}
} // class Property
/**
* Manager for Property
*/
public static class PropertyManager extends TopicBase {
public String topicName="Property";
public transient List<Property> mPropertys=new ArrayList<Property>();
public transient Map<String,Property> mPropertyMap=new LinkedHashMap<String,Property>();
/**
* get my Properties
*/
public List<Property> getProperties() {
List<Property> result=this.mPropertys;
return result;
}
/**
* add a new Property
*/
public Property add(Property pProperty) {
mPropertys.add(pProperty);
mPropertyMap.put(pProperty.getPageid(),pProperty);
return pProperty;
}
/**
* add a new Property from the given triple
*/
public Property add(TripleQuery query,Triple pPropertyTriple) {
Property lProperty=new Property(query,pPropertyTriple);
add(lProperty);
return lProperty;
}
// reinitialize my mProperty map
public void reinit() {
mPropertyMap.clear();
for (Property lProperty:mPropertys) {
mPropertyMap.put(lProperty.getPageid(),lProperty);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static PropertyManager fromJson(String json) {
PropertyManager result=JSON.parseObject(json, PropertyManager.class);
result.reinit();
return result;
}
// default constructor for Property Manager
public PropertyManager() {}
// add Properties from the given query
public void addProperties(TripleQuery pPropertyQuery,TripleQuery query) {
if (pPropertyQuery!=null) {
for (Triple lPropertyTriple:pPropertyQuery.getTriples()) {
add(query,lPropertyTriple);
}
}
}
// construct me from the given triple Query query
public PropertyManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lPropertyQuery=query.query(null,"isA","Property");
addProperties(lPropertyQuery,query);
// then the SMW triplestore
lPropertyQuery=query.query(null,"Property:IsA","Property");
addProperties(lPropertyQuery,query);
init(query);
} // constructor for Property Manager
// >>>{user defined topicmanager code}{Property}{Property}
// <<<{user defined topicmanager code}{Property}{Property}
} // class Property Manager
/**
* Context
* A Context groups some topics like a Namespace/Package
*/
public static class Context extends TopicBase {
public String name;
public String since;
public String master;
public String getName() { return name; }
public void setName(String pName) { name=pName; }
public String getSince() { return since; }
public void setSince(String pSince) { since=pSince; }
public String getMaster() { return master; }
public void setMaster(String pMaster) { master=pMaster; }
/**
* convert this Context to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Context to a WikiSon string
* @return the WikiSon representation of this Context
*/
public String toWikiSon() {
String wikison= "{{Context\n";
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("since",since);
wikison+=toWikiSon("master",master);
wikison+="}}\n";
return wikison;
}
/**
* convert this Context to a SiDIF string
* @return the SiDIF representation of this Context
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Context\n",this.pageid);
siDIF+=propertySiDIF("name",name,"Text");
siDIF+=propertySiDIF("since",since,"Date");
siDIF+=propertySiDIF("master",master,"URL");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Context
*/
public Context() {}
/**
* construct a Context from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pContextTriple - the triple to construct me from
*/
public Context(TripleQuery query,Triple pContextTriple) {
this(query,pContextTriple.getSubject().toString());
} // constructor
/**
* construct a Context from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Context(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:Context_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple sinceTriple=query.selectSingle(pageid,"since",null);
if (sinceTriple==null)
sinceTriple=query.selectSingle(pageid,"Property:Context_since",null);
if (sinceTriple!=null)
since=sinceTriple.getObject().toString();
Triple masterTriple=query.selectSingle(pageid,"master",null);
if (masterTriple==null)
masterTriple=query.selectSingle(pageid,"Property:Context_master",null);
if (masterTriple!=null)
master=masterTriple.getObject().toString();
init(query);
} // constructor for Context
// >>>{user defined topic code}{Context}{Context}
// <<<{user defined topic code}{Context}{Context}
} // class Context
/**
* Manager for Context
*/
public static class ContextManager extends TopicBase {
public String topicName="Context";
public transient List<Context> mContexts=new ArrayList<Context>();
public transient Map<String,Context> mContextMap=new LinkedHashMap<String,Context>();
/**
* get my Contexts
*/
public List<Context> getContexts() {
List<Context> result=this.mContexts;
return result;
}
/**
* add a new Context
*/
public Context add(Context pContext) {
mContexts.add(pContext);
mContextMap.put(pContext.getPageid(),pContext);
return pContext;
}
/**
* add a new Context from the given triple
*/
public Context add(TripleQuery query,Triple pContextTriple) {
Context lContext=new Context(query,pContextTriple);
add(lContext);
return lContext;
}
// reinitialize my mContext map
public void reinit() {
mContextMap.clear();
for (Context lContext:mContexts) {
mContextMap.put(lContext.getPageid(),lContext);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static ContextManager fromJson(String json) {
ContextManager result=JSON.parseObject(json, ContextManager.class);
result.reinit();
return result;
}
// default constructor for Context Manager
public ContextManager() {}
// add Contexts from the given query
public void addContexts(TripleQuery pContextQuery,TripleQuery query) {
if (pContextQuery!=null) {
for (Triple lContextTriple:pContextQuery.getTriples()) {
add(query,lContextTriple);
}
}
}
// construct me from the given triple Query query
public ContextManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lContextQuery=query.query(null,"isA","Context");
addContexts(lContextQuery,query);
// then the SMW triplestore
lContextQuery=query.query(null,"Property:IsA","Context");
addContexts(lContextQuery,query);
init(query);
} // constructor for Context Manager
// >>>{user defined topicmanager code}{Context}{Context}
// <<<{user defined topicmanager code}{Context}{Context}
} // class Context Manager
/**
* Topic
* A Topic is a Concept/Class/Thing/Entity
*/
public static class Topic extends TopicBase {
public String pluralName;
public String documentation;
public String cargo;
public String name;
public String icon;
public String iconUrl;
public String wikiDocumentation;
public String defaultstoremode;
public String listLimit;
public String headerTabs;
public String context;
public String getPluralName() { return pluralName; }
public void setPluralName(String pPluralName) { pluralName=pPluralName; }
public String getDocumentation() { return documentation; }
public void setDocumentation(String pDocumentation) { documentation=pDocumentation; }
public String getCargo() { return cargo; }
public void setCargo(String pCargo) { cargo=pCargo; }
public String getName() { return name; }
public void setName(String pName) { name=pName; }
public String getIcon() { return icon; }
public void setIcon(String pIcon) { icon=pIcon; }
public String getIconUrl() { return iconUrl; }
public void setIconUrl(String pIconUrl) { iconUrl=pIconUrl; }
public String getWikiDocumentation() { return wikiDocumentation; }
public void setWikiDocumentation(String pWikiDocumentation) { wikiDocumentation=pWikiDocumentation; }
public String getDefaultstoremode() { return defaultstoremode; }
public void setDefaultstoremode(String pDefaultstoremode) { defaultstoremode=pDefaultstoremode; }
public String getListLimit() { return listLimit; }
public void setListLimit(String pListLimit) { listLimit=pListLimit; }
public String getHeaderTabs() { return headerTabs; }
public void setHeaderTabs(String pHeaderTabs) { headerTabs=pHeaderTabs; }
public String getContext() { return context; }
public void setContext(String pContext) { context=pContext; }
/**
* convert this Topic to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Topic to a WikiSon string
* @return the WikiSon representation of this Topic
*/
public String toWikiSon() {
String wikison= "{{Topic\n";
wikison+=toWikiSon("pluralName",pluralName);
wikison+=toWikiSon("documentation",documentation);
wikison+=toWikiSon("cargo",cargo);
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("icon",icon);
wikison+=toWikiSon("iconUrl",iconUrl);
wikison+=toWikiSon("wikiDocumentation",wikiDocumentation);
wikison+=toWikiSon("defaultstoremode",defaultstoremode);
wikison+=toWikiSon("listLimit",listLimit);
wikison+=toWikiSon("headerTabs",headerTabs);
wikison+=toWikiSon("context",context);
wikison+="}}\n";
return wikison;
}
/**
* convert this Topic to a SiDIF string
* @return the SiDIF representation of this Topic
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Topic\n",this.pageid);
siDIF+=propertySiDIF("pluralName",pluralName,"Text");
siDIF+=propertySiDIF("documentation",documentation,"Text");
siDIF+=propertySiDIF("cargo",cargo,"Boolean");
siDIF+=propertySiDIF("name",name,"Text");
siDIF+=propertySiDIF("icon",icon,"Page");
siDIF+=propertySiDIF("iconUrl",iconUrl,"Code");
siDIF+=propertySiDIF("wikiDocumentation",wikiDocumentation,"Text");
siDIF+=propertySiDIF("defaultstoremode",defaultstoremode,"Text");
siDIF+=propertySiDIF("listLimit",listLimit,"Number");
siDIF+=propertySiDIF("headerTabs",headerTabs,"Boolean");
siDIF+=propertySiDIF("context",context,"Page");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Topic
*/
public Topic() {}
/**
* construct a Topic from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pTopicTriple - the triple to construct me from
*/
public Topic(TripleQuery query,Triple pTopicTriple) {
this(query,pTopicTriple.getSubject().toString());
} // constructor
/**
* construct a Topic from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Topic(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple pluralNameTriple=query.selectSingle(pageid,"pluralName",null);
if (pluralNameTriple==null)
pluralNameTriple=query.selectSingle(pageid,"Property:Topic_pluralName",null);
if (pluralNameTriple!=null)
pluralName=pluralNameTriple.getObject().toString();
Triple documentationTriple=query.selectSingle(pageid,"documentation",null);
if (documentationTriple==null)
documentationTriple=query.selectSingle(pageid,"Property:Topic_documentation",null);
if (documentationTriple!=null)
documentation=documentationTriple.getObject().toString();
Triple cargoTriple=query.selectSingle(pageid,"cargo",null);
if (cargoTriple==null)
cargoTriple=query.selectSingle(pageid,"Property:Topic_cargo",null);
if (cargoTriple!=null)
cargo=cargoTriple.getObject().toString();
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:Topic_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple iconTriple=query.selectSingle(pageid,"icon",null);
if (iconTriple==null)
iconTriple=query.selectSingle(pageid,"Property:Topic_icon",null);
if (iconTriple!=null)
icon=iconTriple.getObject().toString();
Triple iconUrlTriple=query.selectSingle(pageid,"iconUrl",null);
if (iconUrlTriple==null)
iconUrlTriple=query.selectSingle(pageid,"Property:Topic_iconUrl",null);
if (iconUrlTriple!=null)
iconUrl=iconUrlTriple.getObject().toString();
Triple wikiDocumentationTriple=query.selectSingle(pageid,"wikiDocumentation",null);
if (wikiDocumentationTriple==null)
wikiDocumentationTriple=query.selectSingle(pageid,"Property:Topic_wikiDocumentation",null);
if (wikiDocumentationTriple!=null)
wikiDocumentation=wikiDocumentationTriple.getObject().toString();
Triple defaultstoremodeTriple=query.selectSingle(pageid,"defaultstoremode",null);
if (defaultstoremodeTriple==null)
defaultstoremodeTriple=query.selectSingle(pageid,"Property:Topic_defaultstoremode",null);
if (defaultstoremodeTriple!=null)
defaultstoremode=defaultstoremodeTriple.getObject().toString();
Triple listLimitTriple=query.selectSingle(pageid,"listLimit",null);
if (listLimitTriple==null)
listLimitTriple=query.selectSingle(pageid,"Property:Topic_listLimit",null);
if (listLimitTriple!=null)
listLimit=listLimitTriple.getObject().toString();
Triple headerTabsTriple=query.selectSingle(pageid,"headerTabs",null);
if (headerTabsTriple==null)
headerTabsTriple=query.selectSingle(pageid,"Property:Topic_headerTabs",null);
if (headerTabsTriple!=null)
headerTabs=headerTabsTriple.getObject().toString();
Triple contextTriple=query.selectSingle(pageid,"context",null);
if (contextTriple==null)
contextTriple=query.selectSingle(pageid,"Property:Topic_context",null);
if (contextTriple!=null)
context=contextTriple.getObject().toString();
init(query);
} // constructor for Topic
// >>>{user defined topic code}{Topic}{Topic}
// <<<{user defined topic code}{Topic}{Topic}
} // class Topic
/**
* Manager for Topic
*/
public static class TopicManager extends TopicBase {
public String topicName="Topic";
public transient List<Topic> mTopics=new ArrayList<Topic>();
public transient Map<String,Topic> mTopicMap=new LinkedHashMap<String,Topic>();
/**
* get my Topics
*/
public List<Topic> getTopics() {
List<Topic> result=this.mTopics;
return result;
}
/**
* add a new Topic
*/
public Topic add(Topic pTopic) {
mTopics.add(pTopic);
mTopicMap.put(pTopic.getPageid(),pTopic);
return pTopic;
}
/**
* add a new Topic from the given triple
*/
public Topic add(TripleQuery query,Triple pTopicTriple) {
Topic lTopic=new Topic(query,pTopicTriple);
add(lTopic);
return lTopic;
}
// reinitialize my mTopic map
public void reinit() {
mTopicMap.clear();
for (Topic lTopic:mTopics) {
mTopicMap.put(lTopic.getPageid(),lTopic);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static TopicManager fromJson(String json) {
TopicManager result=JSON.parseObject(json, TopicManager.class);
result.reinit();
return result;
}
// default constructor for Topic Manager
public TopicManager() {}
// add Topics from the given query
public void addTopics(TripleQuery pTopicQuery,TripleQuery query) {
if (pTopicQuery!=null) {
for (Triple lTopicTriple:pTopicQuery.getTriples()) {
add(query,lTopicTriple);
}
}
}
// construct me from the given triple Query query
public TopicManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lTopicQuery=query.query(null,"isA","Topic");
addTopics(lTopicQuery,query);
// then the SMW triplestore
lTopicQuery=query.query(null,"Property:IsA","Topic");
addTopics(lTopicQuery,query);
init(query);
} // constructor for Topic Manager
// >>>{user defined topicmanager code}{Topic}{Topic}
// <<<{user defined topicmanager code}{Topic}{Topic}
} // class Topic Manager
/**
* Action
* An action/function/operation to be performed
*/
public static class Action extends TopicBase {
public String name;
public String servicetype;
public String service;
public String inputtype;
public String input;
public String actionpage;
public String output;
public String engine;
public String author;
public String since;
public String comment;
public String getName() { return name; }
public void setName(String pName) { name=pName; }
public String getServicetype() { return servicetype; }
public void setServicetype(String pServicetype) { servicetype=pServicetype; }
public String getService() { return service; }
public void setService(String pService) { service=pService; }
public String getInputtype() { return inputtype; }
public void setInputtype(String pInputtype) { inputtype=pInputtype; }
public String getInput() { return input; }
public void setInput(String pInput) { input=pInput; }
public String getActionpage() { return actionpage; }
public void setActionpage(String pActionpage) { actionpage=pActionpage; }
public String getOutput() { return output; }
public void setOutput(String pOutput) { output=pOutput; }
public String getEngine() { return engine; }
public void setEngine(String pEngine) { engine=pEngine; }
public String getAuthor() { return author; }
public void setAuthor(String pAuthor) { author=pAuthor; }
public String getSince() { return since; }
public void setSince(String pSince) { since=pSince; }
public String getComment() { return comment; }
public void setComment(String pComment) { comment=pComment; }
/**
* convert this Action to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Action to a WikiSon string
* @return the WikiSon representation of this Action
*/
public String toWikiSon() {
String wikison= "{{Action\n";
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("servicetype",servicetype);
wikison+=toWikiSon("service",service);
wikison+=toWikiSon("inputtype",inputtype);
wikison+=toWikiSon("input",input);
wikison+=toWikiSon("actionpage",actionpage);
wikison+=toWikiSon("output",output);
wikison+=toWikiSon("engine",engine);
wikison+=toWikiSon("author",author);
wikison+=toWikiSon("since",since);
wikison+=toWikiSon("comment",comment);
wikison+="}}\n";
return wikison;
}
/**
* convert this Action to a SiDIF string
* @return the SiDIF representation of this Action
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Action\n",this.pageid);
siDIF+=propertySiDIF("name",name,"Text");
siDIF+=propertySiDIF("servicetype",servicetype,"Text");
siDIF+=propertySiDIF("service",service,"URL");
siDIF+=propertySiDIF("inputtype",inputtype,"Text");
siDIF+=propertySiDIF("input",input,"Code");
siDIF+=propertySiDIF("actionpage",actionpage,"Page");
siDIF+=propertySiDIF("output",output,"Text");
siDIF+=propertySiDIF("engine",engine,"Text");
siDIF+=propertySiDIF("author",author,"Page");
siDIF+=propertySiDIF("since",since,"Date");
siDIF+=propertySiDIF("comment",comment,"Text");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Action
*/
public Action() {}
/**
* construct a Action from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pActionTriple - the triple to construct me from
*/
public Action(TripleQuery query,Triple pActionTriple) {
this(query,pActionTriple.getSubject().toString());
} // constructor
/**
* construct a Action from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Action(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:Action_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple servicetypeTriple=query.selectSingle(pageid,"servicetype",null);
if (servicetypeTriple==null)
servicetypeTriple=query.selectSingle(pageid,"Property:Action_servicetype",null);
if (servicetypeTriple!=null)
servicetype=servicetypeTriple.getObject().toString();
Triple serviceTriple=query.selectSingle(pageid,"service",null);
if (serviceTriple==null)
serviceTriple=query.selectSingle(pageid,"Property:Action_service",null);
if (serviceTriple!=null)
service=serviceTriple.getObject().toString();
Triple inputtypeTriple=query.selectSingle(pageid,"inputtype",null);
if (inputtypeTriple==null)
inputtypeTriple=query.selectSingle(pageid,"Property:Action_inputtype",null);
if (inputtypeTriple!=null)
inputtype=inputtypeTriple.getObject().toString();
Triple inputTriple=query.selectSingle(pageid,"input",null);
if (inputTriple==null)
inputTriple=query.selectSingle(pageid,"Property:Action_input",null);
if (inputTriple!=null)
input=inputTriple.getObject().toString();
Triple actionpageTriple=query.selectSingle(pageid,"actionpage",null);
if (actionpageTriple==null)
actionpageTriple=query.selectSingle(pageid,"Property:Action_actionpage",null);
if (actionpageTriple!=null)
actionpage=actionpageTriple.getObject().toString();
Triple outputTriple=query.selectSingle(pageid,"output",null);
if (outputTriple==null)
outputTriple=query.selectSingle(pageid,"Property:Action_output",null);
if (outputTriple!=null)
output=outputTriple.getObject().toString();
Triple engineTriple=query.selectSingle(pageid,"engine",null);
if (engineTriple==null)
engineTriple=query.selectSingle(pageid,"Property:Action_engine",null);
if (engineTriple!=null)
engine=engineTriple.getObject().toString();
Triple authorTriple=query.selectSingle(pageid,"author",null);
if (authorTriple==null)
authorTriple=query.selectSingle(pageid,"Property:Action_author",null);
if (authorTriple!=null)
author=authorTriple.getObject().toString();
Triple sinceTriple=query.selectSingle(pageid,"since",null);
if (sinceTriple==null)
sinceTriple=query.selectSingle(pageid,"Property:Action_since",null);
if (sinceTriple!=null)
since=sinceTriple.getObject().toString();
Triple commentTriple=query.selectSingle(pageid,"comment",null);
if (commentTriple==null)
commentTriple=query.selectSingle(pageid,"Property:Action_comment",null);
if (commentTriple!=null)
comment=commentTriple.getObject().toString();
init(query);
} // constructor for Action
// >>>{user defined topic code}{Action}{Action}
// <<<{user defined topic code}{Action}{Action}
} // class Action
/**
* Manager for Action
*/
public static class ActionManager extends TopicBase {
public String topicName="Action";
public transient List<Action> mActions=new ArrayList<Action>();
public transient Map<String,Action> mActionMap=new LinkedHashMap<String,Action>();
/**
* get my Actions
*/
public List<Action> getActions() {
List<Action> result=this.mActions;
return result;
}
/**
* add a new Action
*/
public Action add(Action pAction) {
mActions.add(pAction);
mActionMap.put(pAction.getPageid(),pAction);
return pAction;
}
/**
* add a new Action from the given triple
*/
public Action add(TripleQuery query,Triple pActionTriple) {
Action lAction=new Action(query,pActionTriple);
add(lAction);
return lAction;
}
// reinitialize my mAction map
public void reinit() {
mActionMap.clear();
for (Action lAction:mActions) {
mActionMap.put(lAction.getPageid(),lAction);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static ActionManager fromJson(String json) {
ActionManager result=JSON.parseObject(json, ActionManager.class);
result.reinit();
return result;
}
// default constructor for Action Manager
public ActionManager() {}
// add Actions from the given query
public void addActions(TripleQuery pActionQuery,TripleQuery query) {
if (pActionQuery!=null) {
for (Triple lActionTriple:pActionQuery.getTriples()) {
add(query,lActionTriple);
}
}
}
// construct me from the given triple Query query
public ActionManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lActionQuery=query.query(null,"isA","Action");
addActions(lActionQuery,query);
// then the SMW triplestore
lActionQuery=query.query(null,"Property:IsA","Action");
addActions(lActionQuery,query);
init(query);
} // constructor for Action Manager
// >>>{user defined topicmanager code}{Action}{Action}
// <<<{user defined topicmanager code}{Action}{Action}
} // class Action Manager
/**
* TopicLink
* A TopicLink links two Concepts
*/
public static class TopicLink extends TopicBase {
public String masterDetail;
public String name;
public String source;
public String sourceRole;
public String sourceMultiple;
public String sourceDocumentation;
public String target;
public String targetRole;
public String targetMultiple;
public String targetDocumentation;
public String getMasterDetail() { return masterDetail; }
public void setMasterDetail(String pMasterDetail) { masterDetail=pMasterDetail; }
public String getName() { return name; }
public void setName(String pName) { name=pName; }
public String getSource() { return source; }
public void setSource(String pSource) { source=pSource; }
public String getSourceRole() { return sourceRole; }
public void setSourceRole(String pSourceRole) { sourceRole=pSourceRole; }
public String getSourceMultiple() { return sourceMultiple; }
public void setSourceMultiple(String pSourceMultiple) { sourceMultiple=pSourceMultiple; }
public String getSourceDocumentation() { return sourceDocumentation; }
public void setSourceDocumentation(String pSourceDocumentation) { sourceDocumentation=pSourceDocumentation; }
public String getTarget() { return target; }
public void setTarget(String pTarget) { target=pTarget; }
public String getTargetRole() { return targetRole; }
public void setTargetRole(String pTargetRole) { targetRole=pTargetRole; }
public String getTargetMultiple() { return targetMultiple; }
public void setTargetMultiple(String pTargetMultiple) { targetMultiple=pTargetMultiple; }
public String getTargetDocumentation() { return targetDocumentation; }
public void setTargetDocumentation(String pTargetDocumentation) { targetDocumentation=pTargetDocumentation; }
/**
* convert this TopicLink to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this TopicLink to a WikiSon string
* @return the WikiSon representation of this TopicLink
*/
public String toWikiSon() {
String wikison= "{{TopicLink\n";
wikison+=toWikiSon("masterDetail",masterDetail);
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("source",source);
wikison+=toWikiSon("sourceRole",sourceRole);
wikison+=toWikiSon("sourceMultiple",sourceMultiple);
wikison+=toWikiSon("sourceDocumentation",sourceDocumentation);
wikison+=toWikiSon("target",target);
wikison+=toWikiSon("targetRole",targetRole);
wikison+=toWikiSon("targetMultiple",targetMultiple);
wikison+=toWikiSon("targetDocumentation",targetDocumentation);
wikison+="}}\n";
return wikison;
}
/**
* convert this TopicLink to a SiDIF string
* @return the SiDIF representation of this TopicLink
*/
public String toSiDIF() {
String siDIF = String.format("%s isA TopicLink\n",this.pageid);
siDIF+=propertySiDIF("masterDetail",masterDetail,"Boolean");
siDIF+=propertySiDIF("name",name,"Text");
siDIF+=propertySiDIF("source",source,"Page");
siDIF+=propertySiDIF("sourceRole",sourceRole,"Text");
siDIF+=propertySiDIF("sourceMultiple",sourceMultiple,"Boolean");
siDIF+=propertySiDIF("sourceDocumentation",sourceDocumentation,"Text");
siDIF+=propertySiDIF("target",target,"Page");
siDIF+=propertySiDIF("targetRole",targetRole,"Text");
siDIF+=propertySiDIF("targetMultiple",targetMultiple,"Boolean");
siDIF+=propertySiDIF("targetDocumentation",targetDocumentation,"Text");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for TopicLink
*/
public TopicLink() {}
/**
* construct a TopicLink from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pTopicLinkTriple - the triple to construct me from
*/
public TopicLink(TripleQuery query,Triple pTopicLinkTriple) {
this(query,pTopicLinkTriple.getSubject().toString());
} // constructor
/**
* construct a TopicLink from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public TopicLink(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple masterDetailTriple=query.selectSingle(pageid,"masterDetail",null);
if (masterDetailTriple==null)
masterDetailTriple=query.selectSingle(pageid,"Property:TopicLink_masterDetail",null);
if (masterDetailTriple!=null)
masterDetail=masterDetailTriple.getObject().toString();
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:TopicLink_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple sourceTriple=query.selectSingle(pageid,"source",null);
if (sourceTriple==null)
sourceTriple=query.selectSingle(pageid,"Property:TopicLink_source",null);
if (sourceTriple!=null)
source=sourceTriple.getObject().toString();
Triple sourceRoleTriple=query.selectSingle(pageid,"sourceRole",null);
if (sourceRoleTriple==null)
sourceRoleTriple=query.selectSingle(pageid,"Property:TopicLink_sourceRole",null);
if (sourceRoleTriple!=null)
sourceRole=sourceRoleTriple.getObject().toString();
Triple sourceMultipleTriple=query.selectSingle(pageid,"sourceMultiple",null);
if (sourceMultipleTriple==null)
sourceMultipleTriple=query.selectSingle(pageid,"Property:TopicLink_sourceMultiple",null);
if (sourceMultipleTriple!=null)
sourceMultiple=sourceMultipleTriple.getObject().toString();
Triple sourceDocumentationTriple=query.selectSingle(pageid,"sourceDocumentation",null);
if (sourceDocumentationTriple==null)
sourceDocumentationTriple=query.selectSingle(pageid,"Property:TopicLink_sourceDocumentation",null);
if (sourceDocumentationTriple!=null)
sourceDocumentation=sourceDocumentationTriple.getObject().toString();
Triple targetTriple=query.selectSingle(pageid,"target",null);
if (targetTriple==null)
targetTriple=query.selectSingle(pageid,"Property:TopicLink_target",null);
if (targetTriple!=null)
target=targetTriple.getObject().toString();
Triple targetRoleTriple=query.selectSingle(pageid,"targetRole",null);
if (targetRoleTriple==null)
targetRoleTriple=query.selectSingle(pageid,"Property:TopicLink_targetRole",null);
if (targetRoleTriple!=null)
targetRole=targetRoleTriple.getObject().toString();
Triple targetMultipleTriple=query.selectSingle(pageid,"targetMultiple",null);
if (targetMultipleTriple==null)
targetMultipleTriple=query.selectSingle(pageid,"Property:TopicLink_targetMultiple",null);
if (targetMultipleTriple!=null)
targetMultiple=targetMultipleTriple.getObject().toString();
Triple targetDocumentationTriple=query.selectSingle(pageid,"targetDocumentation",null);
if (targetDocumentationTriple==null)
targetDocumentationTriple=query.selectSingle(pageid,"Property:TopicLink_targetDocumentation",null);
if (targetDocumentationTriple!=null)
targetDocumentation=targetDocumentationTriple.getObject().toString();
init(query);
} // constructor for TopicLink
// >>>{user defined topic code}{TopicLink}{TopicLink}
// <<<{user defined topic code}{TopicLink}{TopicLink}
} // class TopicLink
/**
* Manager for TopicLink
*/
public static class TopicLinkManager extends TopicBase {
public String topicName="TopicLink";
public transient List<TopicLink> mTopicLinks=new ArrayList<TopicLink>();
public transient Map<String,TopicLink> mTopicLinkMap=new LinkedHashMap<String,TopicLink>();
/**
* get my TopicLinks
*/
public List<TopicLink> getTopicLinks() {
List<TopicLink> result=this.mTopicLinks;
return result;
}
/**
* add a new TopicLink
*/
public TopicLink add(TopicLink pTopicLink) {
mTopicLinks.add(pTopicLink);
mTopicLinkMap.put(pTopicLink.getPageid(),pTopicLink);
return pTopicLink;
}
/**
* add a new TopicLink from the given triple
*/
public TopicLink add(TripleQuery query,Triple pTopicLinkTriple) {
TopicLink lTopicLink=new TopicLink(query,pTopicLinkTriple);
add(lTopicLink);
return lTopicLink;
}
// reinitialize my mTopicLink map
public void reinit() {
mTopicLinkMap.clear();
for (TopicLink lTopicLink:mTopicLinks) {
mTopicLinkMap.put(lTopicLink.getPageid(),lTopicLink);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static TopicLinkManager fromJson(String json) {
TopicLinkManager result=JSON.parseObject(json, TopicLinkManager.class);
result.reinit();
return result;
}
// default constructor for TopicLink Manager
public TopicLinkManager() {}
// add TopicLinks from the given query
public void addTopicLinks(TripleQuery pTopicLinkQuery,TripleQuery query) {
if (pTopicLinkQuery!=null) {
for (Triple lTopicLinkTriple:pTopicLinkQuery.getTriples()) {
add(query,lTopicLinkTriple);
}
}
}
// construct me from the given triple Query query
public TopicLinkManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lTopicLinkQuery=query.query(null,"isA","TopicLink");
addTopicLinks(lTopicLinkQuery,query);
// then the SMW triplestore
lTopicLinkQuery=query.query(null,"Property:IsA","TopicLink");
addTopicLinks(lTopicLinkQuery,query);
init(query);
} // constructor for TopicLink Manager
// >>>{user defined topicmanager code}{TopicLink}{TopicLink}
// <<<{user defined topicmanager code}{TopicLink}{TopicLink}
} // class TopicLink Manager
}