Difference between revisions of "GenerateRoyalPages"

From BITPlan royal-family Wiki
Jump to navigation Jump to search
Line 23: Line 23:
 
@import com.bitplan.mediawiki.japi.Mediawiki
 
@import com.bitplan.mediawiki.japi.Mediawiki
 
@import com.bitplan.mediawiki.japi.api.Api
 
@import com.bitplan.mediawiki.japi.api.Api
@include(wiki.SiDIFTemplates.propertiesdefs)
+
@include(wiki.PersonJava.Code)
 
@args() {
 
@args() {
 
   String title  
 
   String title  
Line 31: Line 31:
 
}
 
}
 
@// create the given person
 
@// create the given person
@def createPerson(String name) {
+
@def createPerson(Person p) {
 
@{
 
@{
 
   Throwable error=null;
 
   Throwable error=null;
Line 37: Line 37:
 
     String pageTitle=name;
 
     String pageTitle=name;
 
     SSLWiki wiki=(SSLWiki)wikiTask.getWiki();
 
     SSLWiki wiki=(SSLWiki)wikiTask.getWiki();
     String pageContent="{{Person|name="+name+"}}";
+
     String pageContent=p.toWikiSon();
 
     String summary="generated by GenerateRoyalPages at "+wiki.getIsoTimeStamp();
 
     String summary="generated by GenerateRoyalPages at "+wiki.getIsoTimeStamp();
 
     wiki.edit(pageTitle,pageContent,summary);
 
     wiki.edit(pageTitle,pageContent,summary);
Line 52: Line 52:
 
   TripleQuery personQuery=query.query(null,"isA","Person");
 
   TripleQuery personQuery=query.query(null,"isA","Person");
 
   TripleQuery familyQuery=query.query(null,"isA","Family");
 
   TripleQuery familyQuery=query.query(null,"isA","Family");
 +
  PersonManager pm=new PersonManager(personQuery);
 +
  FamilyManager fm=new FamilyManager(familyQuery);
 +
  int pCount=0;
 +
  int pMax=3;
 
   //Triple contextTriple=query.selectSingle(null,"isA","Context");
 
   //Triple contextTriple=query.selectSingle(null,"isA","Context");
 
   //String contextName=contextTriple.getSubject().toString();
 
   //String contextName=contextTriple.getSubject().toString();
Line 61: Line 65:
 
*@(personQuery.size()) persons found
 
*@(personQuery.size()) persons found
 
*@(familyQuery.size()) families found
 
*@(familyQuery.size()) families found
@createPerson("Victoria_Hanover")
+
@for (Person p:pm.getPersons()) {
 +
@createPerson(p)
 +
@{
 +
  pCount++;
 +
  if (pCount>=pMax) {
 +
    break;
 +
  }
 +
}
 +
}
 
</source>
 
</source>
 
{{#default_form:Action}}
 
{{#default_form:Action}}

Revision as of 08:38, 6 October 2017

Action
edit
name  GenerateRoyalPages
servicetype  WikiTask
service  
inputtype  Page
input  Royal92#sidif
actionpage  GenerateRoyalPages#template
output  Royal92/pages
engine  rythm
author  Wf
since  2017/10/06
comment  Create wiki pages for Royal-Family

login reset runtemplate -> Royal92/pages

[edit]
@// This is a rythm template
@import org.sidif.triple.TripleQuery
@import org.sidif.triple.Triple
@import org.sidif.wiki.SSLWiki
@import com.bitplan.topic.ContextSetting.TripleStoreMode
@import com.alibaba.fastjson.JSON
@import com.bitplan.mediawiki.japi.MediawikiApi
@import com.bitplan.mediawiki.japi.Mediawiki
@import com.bitplan.mediawiki.japi.api.Api
@include(wiki.PersonJava.Code)
@args() {
  String title 
  String logo
  org.sidif.wiki.WikiTask wikiTask
  org.sidif.triple.TripleStore tripleStore
}
@// create the given person
@def createPerson(Person p) {
@{
  Throwable error=null;
  try {  
    String pageTitle=name;
    SSLWiki wiki=(SSLWiki)wikiTask.getWiki();
    String pageContent=p.toWikiSon();
    String summary="generated by GenerateRoyalPages at "+wiki.getIsoTimeStamp();
    wiki.edit(pageTitle,pageContent,summary);
  } catch (Throwable th) {
    error=th;
  }
}
@if (error) {
<span style='color:red'>Error: @(error.getMessage())</span>
}
}
@{
  TripleQuery query=tripleStore.query();
  TripleQuery personQuery=query.query(null,"isA","Person");
  TripleQuery familyQuery=query.query(null,"isA","Family");
  PersonManager pm=new PersonManager(personQuery);
  FamilyManager fm=new FamilyManager(familyQuery);
  int pCount=0;
  int pMax=3;
  //Triple contextTriple=query.selectSingle(null,"isA","Context");
  //String contextName=contextTriple.getSubject().toString();
  //Triple sidifTriple=query.selectSingle(contextName,"sidif", null);
  //String contextSidif=sidifTriple.getObject().toString();
}
@(wikiTask.getWiki().getIsoTimeStamp())
*@(query.size()) triples found
*@(personQuery.size()) persons found
*@(familyQuery.size()) families found
@for (Person p:pm.getPersons()) {
@createPerson(p)
@{
  pCount++;
  if (pCount>=pMax) {
    break;
  }
}
}