Difference between revisions of "Concept:Step/Java"

From BITPlan Wiki
Jump to navigation Jump to search
m (created by WikiTask 2019-04-26T07:13:04Z)
m (created by WikiTask 2019-04-26T11:18:33Z)
 
Line 349: Line 349:
 
     public String kind;
 
     public String kind;
 
     public String reference;
 
     public String reference;
 +
    public String javadoc;
 
     public String text;
 
     public String text;
 
     public String test;
 
     public String test;
Line 359: Line 360:
 
     public String getReference() { return reference; }
 
     public String getReference() { return reference; }
 
     public void setReference(String pReference) { reference=pReference; }
 
     public void setReference(String pReference) { reference=pReference; }
 +
    public String getJavadoc() { return javadoc; }
 +
    public void setJavadoc(String pJavadoc) { javadoc=pJavadoc; }
 
     public String getText() { return text; }
 
     public String getText() { return text; }
 
     public void setText(String pText) { text=pText; }
 
     public void setText(String pText) { text=pText; }
Line 379: Line 382:
 
       wikison+=toWikiSon("kind",kind);
 
       wikison+=toWikiSon("kind",kind);
 
       wikison+=toWikiSon("reference",reference);
 
       wikison+=toWikiSon("reference",reference);
 +
      wikison+=toWikiSon("javadoc",javadoc);
 
       wikison+=toWikiSon("text",text);
 
       wikison+=toWikiSon("text",text);
 
       wikison+=toWikiSon("test",test);
 
       wikison+=toWikiSon("test",test);
Line 395: Line 399:
 
       siDIF+=propertySiDIF("kind",kind,"Text");
 
       siDIF+=propertySiDIF("kind",kind,"Text");
 
       siDIF+=propertySiDIF("reference",reference,"External Identifier");
 
       siDIF+=propertySiDIF("reference",reference,"External Identifier");
 +
      siDIF+=propertySiDIF("javadoc",javadoc,"External Identifier");
 
       siDIF+=propertySiDIF("text",text,"Text");
 
       siDIF+=propertySiDIF("text",text,"Text");
 
       siDIF+=propertySiDIF("test",test,"Text");
 
       siDIF+=propertySiDIF("test",test,"Text");
Line 442: Line 447:
 
       if (referenceTriple!=null)  
 
       if (referenceTriple!=null)  
 
         reference=referenceTriple.getObject().toString();
 
         reference=referenceTriple.getObject().toString();
 +
      Triple javadocTriple=query.selectSingle(pageid,"javadoc",null);
 +
      if (javadocTriple==null)
 +
        javadocTriple=query.selectSingle(pageid,"Property:Step_javadoc",null);
 +
      if (javadocTriple!=null)
 +
        javadoc=javadocTriple.getObject().toString();
 
       Triple textTriple=query.selectSingle(pageid,"text",null);
 
       Triple textTriple=query.selectSingle(pageid,"text",null);
 
       if (textTriple==null)
 
       if (textTriple==null)

Latest revision as of 12:18, 26 April 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
 /**
  * SimpleGraphModule
  * A SimpleGraphModule is an Apache/TinkerPop API wrapper for a system
  */
  public static class SimpleGraphModule extends TopicBase {
  
    public String name;
    public String logo;
    public String modulename;
    public String systemname;
    public String url;
    public String apiname;
    public String apiurl;
    public String issue;
    public String documentation;
    public String forSE;

    public String getName() { return name; }
    public void setName(String pName) { name=pName; }
    public String getLogo() { return logo; }
    public void setLogo(String pLogo) { logo=pLogo; }
    public String getModulename() { return modulename; }
    public void setModulename(String pModulename) { modulename=pModulename; }
    public String getSystemname() { return systemname; }
    public void setSystemname(String pSystemname) { systemname=pSystemname; }
    public String getUrl() { return url; }
    public void setUrl(String pUrl) { url=pUrl; }
    public String getApiname() { return apiname; }
    public void setApiname(String pApiname) { apiname=pApiname; }
    public String getApiurl() { return apiurl; }
    public void setApiurl(String pApiurl) { apiurl=pApiurl; }
    public String getIssue() { return issue; }
    public void setIssue(String pIssue) { issue=pIssue; }
    public String getDocumentation() { return documentation; }
    public void setDocumentation(String pDocumentation) { documentation=pDocumentation; }
    public String getForSE() { return forSE; }
    public void setForSE(String pForSE) { forSE=pForSE; }
    /**
     * convert this SimpleGraphModule to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this SimpleGraphModule to a WikiSon string
     * @return the WikiSon representation of this SimpleGraphModule
     */
    public String toWikiSon() {
      String wikison= "{{SimpleGraphModule\n";
      wikison+=toWikiSon("name",name);
      wikison+=toWikiSon("logo",logo);
      wikison+=toWikiSon("modulename",modulename);
      wikison+=toWikiSon("systemname",systemname);
      wikison+=toWikiSon("url",url);
      wikison+=toWikiSon("apiname",apiname);
      wikison+=toWikiSon("apiurl",apiurl);
      wikison+=toWikiSon("issue",issue);
      wikison+=toWikiSon("documentation",documentation);
      wikison+=toWikiSon("forSE",forSE);
      wikison+="}}\n";
      return wikison;
    }

    /**
     * convert this SimpleGraphModule to a SiDIF string
     * @return the SiDIF representation of this SimpleGraphModule
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA SimpleGraphModule\n",this.pageid);
      siDIF+=propertySiDIF("name",name,"Text");
      siDIF+=propertySiDIF("logo",logo,"Page");
      siDIF+=propertySiDIF("modulename",modulename,"Text");
      siDIF+=propertySiDIF("systemname",systemname,"Text");
      siDIF+=propertySiDIF("url",url,"URI");
      siDIF+=propertySiDIF("apiname",apiname,"Text");
      siDIF+=propertySiDIF("apiurl",apiurl,"URI");
      siDIF+=propertySiDIF("issue",issue,"ExternalIdentifier");
      siDIF+=propertySiDIF("documentation",documentation,"Text");
      siDIF+=propertySiDIF("forSE",forSE,"Boolean");
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

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

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

    /**
     * construct a SimpleGraphModule from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public SimpleGraphModule(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple nameTriple=query.selectSingle(pageid,"name",null);
      if (nameTriple==null)
        nameTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_name",null);
      if (nameTriple!=null) 
        name=nameTriple.getObject().toString();
      Triple logoTriple=query.selectSingle(pageid,"logo",null);
      if (logoTriple==null)
        logoTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_logo",null);
      if (logoTriple!=null) 
        logo=logoTriple.getObject().toString();
      Triple modulenameTriple=query.selectSingle(pageid,"modulename",null);
      if (modulenameTriple==null)
        modulenameTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_modulename",null);
      if (modulenameTriple!=null) 
        modulename=modulenameTriple.getObject().toString();
      Triple systemnameTriple=query.selectSingle(pageid,"systemname",null);
      if (systemnameTriple==null)
        systemnameTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_systemname",null);
      if (systemnameTriple!=null) 
        systemname=systemnameTriple.getObject().toString();
      Triple urlTriple=query.selectSingle(pageid,"url",null);
      if (urlTriple==null)
        urlTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_url",null);
      if (urlTriple!=null) 
        url=urlTriple.getObject().toString();
      Triple apinameTriple=query.selectSingle(pageid,"apiname",null);
      if (apinameTriple==null)
        apinameTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_apiname",null);
      if (apinameTriple!=null) 
        apiname=apinameTriple.getObject().toString();
      Triple apiurlTriple=query.selectSingle(pageid,"apiurl",null);
      if (apiurlTriple==null)
        apiurlTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_apiurl",null);
      if (apiurlTriple!=null) 
        apiurl=apiurlTriple.getObject().toString();
      Triple issueTriple=query.selectSingle(pageid,"issue",null);
      if (issueTriple==null)
        issueTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_issue",null);
      if (issueTriple!=null) 
        issue=issueTriple.getObject().toString();
      Triple documentationTriple=query.selectSingle(pageid,"documentation",null);
      if (documentationTriple==null)
        documentationTriple=query.selectSingle(pageid,"Property:SimpleGraphModule_documentation",null);
      if (documentationTriple!=null) 
        documentation=documentationTriple.getObject().toString();
      Triple forSETriple=query.selectSingle(pageid,"forSE",null);
      if (forSETriple==null)
        forSETriple=query.selectSingle(pageid,"Property:SimpleGraphModule_forSE",null);
      if (forSETriple!=null) 
        forSE=forSETriple.getObject().toString();
      init(query);
    } // constructor for SimpleGraphModule
    
    // >>>{user defined topic code}{SimpleGraphModule}{SimpleGraphModule}
    // <<<{user defined topic code}{SimpleGraphModule}{SimpleGraphModule}
  } // class SimpleGraphModule
  /**
   * Manager for SimpleGraphModule
   */
  public static class SimpleGraphModuleManager extends TopicBase {
 
    public String topicName="SimpleGraphModule";
    public transient List<SimpleGraphModule> mSimpleGraphModules=new ArrayList<SimpleGraphModule>();
    public transient Map<String,SimpleGraphModule> mSimpleGraphModuleMap=new LinkedHashMap<String,SimpleGraphModule>();

    /**
     * get my SimpleGraphModules
     */
    public List<SimpleGraphModule> getSimpleGraphModules() {
      List<SimpleGraphModule> result=this.mSimpleGraphModules;
      return result;
    }

    /**
     *  add a new SimpleGraphModule 
     */
    public SimpleGraphModule add(SimpleGraphModule pSimpleGraphModule) {
      mSimpleGraphModules.add(pSimpleGraphModule);
      mSimpleGraphModuleMap.put(pSimpleGraphModule.getPageid(),pSimpleGraphModule);
      return pSimpleGraphModule;
    }

    /**
     *  add a new SimpleGraphModule from the given triple
     */
    public SimpleGraphModule add(TripleQuery query,Triple pSimpleGraphModuleTriple) {
      SimpleGraphModule lSimpleGraphModule=new SimpleGraphModule(query,pSimpleGraphModuleTriple);
      add(lSimpleGraphModule);
      return lSimpleGraphModule;
    }

    // reinitialize my mSimpleGraphModule map
    public void reinit() {
      mSimpleGraphModuleMap.clear();
      for (SimpleGraphModule lSimpleGraphModule:mSimpleGraphModules) {
        mSimpleGraphModuleMap.put(lSimpleGraphModule.getPageid(),lSimpleGraphModule);
      }
    }

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

    // default constructor for SimpleGraphModule Manager
    public SimpleGraphModuleManager() {}

    // add SimpleGraphModules from the given query
    public void addSimpleGraphModules(TripleQuery pSimpleGraphModuleQuery,TripleQuery query) {
      if (pSimpleGraphModuleQuery!=null) {
        for (Triple lSimpleGraphModuleTriple:pSimpleGraphModuleQuery.getTriples()) {
          add(query,lSimpleGraphModuleTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public SimpleGraphModuleManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lSimpleGraphModuleQuery=query.query(null,"isA","SimpleGraphModule");
      addSimpleGraphModules(lSimpleGraphModuleQuery,query);
      // then the SMW triplestore
      lSimpleGraphModuleQuery=query.query(null,"Property:IsA","SimpleGraphModule");
      addSimpleGraphModules(lSimpleGraphModuleQuery,query);
      init(query);
    } // constructor for SimpleGraphModule Manager
    
    // >>>{user defined topicmanager code}{SimpleGraphModule}{SimpleGraphModule}
    // <<<{user defined topicmanager code}{SimpleGraphModule}{SimpleGraphModule}
  } // class SimpleGraphModule Manager
 /**
  * Step
  * A Step is a Graph Traversal Step in the Gremlin language - you can think of it as in instruction an a graph computer
  */
  public static class Step extends TopicBase {
  
    public String name;
    public String kind;
    public String reference;
    public String javadoc;
    public String text;
    public String test;
    public String level;

    public String getName() { return name; }
    public void setName(String pName) { name=pName; }
    public String getKind() { return kind; }
    public void setKind(String pKind) { kind=pKind; }
    public String getReference() { return reference; }
    public void setReference(String pReference) { reference=pReference; }
    public String getJavadoc() { return javadoc; }
    public void setJavadoc(String pJavadoc) { javadoc=pJavadoc; }
    public String getText() { return text; }
    public void setText(String pText) { text=pText; }
    public String getTest() { return test; }
    public void setTest(String pTest) { test=pTest; }
    public String getLevel() { return level; }
    public void setLevel(String pLevel) { level=pLevel; }
    /**
     * convert this Step to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this Step to a WikiSon string
     * @return the WikiSon representation of this Step
     */
    public String toWikiSon() {
      String wikison= "{{Step\n";
      wikison+=toWikiSon("name",name);
      wikison+=toWikiSon("kind",kind);
      wikison+=toWikiSon("reference",reference);
      wikison+=toWikiSon("javadoc",javadoc);
      wikison+=toWikiSon("text",text);
      wikison+=toWikiSon("test",test);
      wikison+=toWikiSon("level",level);
      wikison+="}}\n";
      return wikison;
    }

    /**
     * convert this Step to a SiDIF string
     * @return the SiDIF representation of this Step
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA Step\n",this.pageid);
      siDIF+=propertySiDIF("name",name,"Text");
      siDIF+=propertySiDIF("kind",kind,"Text");
      siDIF+=propertySiDIF("reference",reference,"External Identifier");
      siDIF+=propertySiDIF("javadoc",javadoc,"External Identifier");
      siDIF+=propertySiDIF("text",text,"Text");
      siDIF+=propertySiDIF("test",test,"Text");
      siDIF+=propertySiDIF("level",level,"Number");
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

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

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

    /**
     * construct a Step from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public Step(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple nameTriple=query.selectSingle(pageid,"name",null);
      if (nameTriple==null)
        nameTriple=query.selectSingle(pageid,"Property:Step_name",null);
      if (nameTriple!=null) 
        name=nameTriple.getObject().toString();
      Triple kindTriple=query.selectSingle(pageid,"kind",null);
      if (kindTriple==null)
        kindTriple=query.selectSingle(pageid,"Property:Step_kind",null);
      if (kindTriple!=null) 
        kind=kindTriple.getObject().toString();
      Triple referenceTriple=query.selectSingle(pageid,"reference",null);
      if (referenceTriple==null)
        referenceTriple=query.selectSingle(pageid,"Property:Step_reference",null);
      if (referenceTriple!=null) 
        reference=referenceTriple.getObject().toString();
      Triple javadocTriple=query.selectSingle(pageid,"javadoc",null);
      if (javadocTriple==null)
        javadocTriple=query.selectSingle(pageid,"Property:Step_javadoc",null);
      if (javadocTriple!=null) 
        javadoc=javadocTriple.getObject().toString();
      Triple textTriple=query.selectSingle(pageid,"text",null);
      if (textTriple==null)
        textTriple=query.selectSingle(pageid,"Property:Step_text",null);
      if (textTriple!=null) 
        text=textTriple.getObject().toString();
      Triple testTriple=query.selectSingle(pageid,"test",null);
      if (testTriple==null)
        testTriple=query.selectSingle(pageid,"Property:Step_test",null);
      if (testTriple!=null) 
        test=testTriple.getObject().toString();
      Triple levelTriple=query.selectSingle(pageid,"level",null);
      if (levelTriple==null)
        levelTriple=query.selectSingle(pageid,"Property:Step_level",null);
      if (levelTriple!=null) 
        level=levelTriple.getObject().toString();
      init(query);
    } // constructor for Step
    
    // >>>{user defined topic code}{Step}{Step}
    // <<<{user defined topic code}{Step}{Step}
  } // class Step
  /**
   * Manager for Step
   */
  public static class StepManager extends TopicBase {
 
    public String topicName="Step";
    public transient List<Step> mSteps=new ArrayList<Step>();
    public transient Map<String,Step> mStepMap=new LinkedHashMap<String,Step>();

    /**
     * get my Steps
     */
    public List<Step> getSteps() {
      List<Step> result=this.mSteps;
      return result;
    }

    /**
     *  add a new Step 
     */
    public Step add(Step pStep) {
      mSteps.add(pStep);
      mStepMap.put(pStep.getPageid(),pStep);
      return pStep;
    }

    /**
     *  add a new Step from the given triple
     */
    public Step add(TripleQuery query,Triple pStepTriple) {
      Step lStep=new Step(query,pStepTriple);
      add(lStep);
      return lStep;
    }

    // reinitialize my mStep map
    public void reinit() {
      mStepMap.clear();
      for (Step lStep:mSteps) {
        mStepMap.put(lStep.getPageid(),lStep);
      }
    }

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

    // default constructor for Step Manager
    public StepManager() {}

    // add Steps from the given query
    public void addSteps(TripleQuery pStepQuery,TripleQuery query) {
      if (pStepQuery!=null) {
        for (Triple lStepTriple:pStepQuery.getTriples()) {
          add(query,lStepTriple);
        }
      }
    }

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

}
Showing below 0 pages.

Retrieved from "https://wiki.bitplan.com/index.php?title=Concept:Step/Java&oldid=8904#smw-result"