Package Question17_10

Examples of Question17_10.Element


        this(new DefaultJDOMFactory());
    }

    @Override
    protected Object createNode(final String name) {
        final Element element = documentFactory.element(encodeNode(name));
        final Element parent = top();
        if (parent != null) {
            parent.addContent(element);
        }
        return element;
    }
View Full Code Here


     * Creates a config XML element for this class.
     */
    @Override
    public Element getAsElement()
    {
        Element keyEl = new Element(Element_Key);
        keyEl.setAttribute(Attr_Special, this.key.toString());
        keyEl.setAttribute("length", String.valueOf(this.keyWidth));
        return keyEl;
    }
View Full Code Here

    protected void loadData(Element data)
    {
        if (data == null)
            throw new IllegalArgumentException("cannot load data, data ist null");

        Element li = data.getChild(Element_LanguageInfo);
        name = li.getAttributeValue(Attr_Name);
        nativeName = li.getAttributeValue(Attr_Name);
        fontName = li.getAttributeValue(Attr_Font);
        fixedWidthFontName = li.getAttributeValue(Attr_FixedWidthFont);
        localeString.add(li.getAttributeValue(Attr_LocaleString));
        Element countriesEl = li.getChild(ELEMENT_COUNTRIES);
        if (countriesEl != null)
        {
            List<Element> countries = countriesEl.getChildren(ELEMENT_COUNTRY);
            String[] locSplit = localeString.get(0).split("-");
            if (countries != null && !countries.isEmpty() && locSplit != null && locSplit.length >= 1)
                for (Element country : countries)
                    localeString.add(locSplit[0] + "-" + country.getAttributeValue(ATTR_CODE));
        }
        org = new LinkedList<String>();
        trans = new LinkedList<String>();

        // check the translated keys
        Element transKeys = li.getChild(Show);
        if (transKeys != null)
            for (Element l : transKeys.getChildren(in))
            {
                org.add(l.getAttribute("org").getValue());
                trans.add(l.getAttribute("translate").getValue());
            }
View Full Code Here

        return localeString;
    }

    public Element getAsElement()
    {
        Element root = new Element("KeyboardConfiguration");
        Element li = new Element(Element_LanguageInfo);
        root.addContent(li);
        li.setAttribute(Attr_Name, name);
        li.setAttribute(Attr_NativeName, nativeName);
        li.setAttribute(Attr_Font, fontName);
        li.setAttribute(Attr_FixedWidthFont, fixedWidthFontName);
        li.setAttribute(Attr_LocaleString, localeString.isEmpty() ? "international" : localeString.get(0));
        if (localeString.size() > 1)
        {
            Element countries = new Element(ELEMENT_COUNTRIES);
            for (int i = 1; i < localeString.size(); i++)
            {
                String[] split = localeString.get(i).split("-");
                if (split != null && split.length == 2)
                {
                    Element country = new Element(ELEMENT_COUNTRY);
                    country.setAttribute(ATTR_CODE, split[1]);
                    countries.addContent(country);
                }
            }
            if (countries.getChildren().isEmpty())
                li.addContent(countries);
        }
        Element keyboard;

        // backwards Translation key
        if (org.size() > 0)
        {
            Element et = new Element(Show);
            li.setContent(et);
            for (int f = 0; f < org.size(); f++)
            {
                Element ett = new Element(in);
                et.addContent(ett);
                ett.setAttribute(new org.jdom2.Attribute("org", org.get(f)));
                ett.setAttribute(new org.jdom2.Attribute("translate", trans.get(f)));
            }
        }

        if (imeList.size() > 0)
            for (int f = 0; f < imeList.size(); f++)
            {
                Element et = new Element(IME);
                et.setAttribute(new org.jdom2.Attribute(IME, imeList.get(f)));
                li.addContent(et);
            }

        for (int i = 0; i < size(); i++)
        {
            keyboard = new Element(Element_Keyboard);
            li.addContent(keyboard);

            for (LinkedList<KeyboardKey> list : this.get(i))
            {
                Element line = new Element(Element_Line);
                keyboard.addContent(line);
                for (KeyboardKey kk : list)
                    line.addContent(kk.getAsElement());
            }
        }

        return root;
    }
View Full Code Here

            insertString(textField, keyboard, getContent(keyboard.getModifier()));
    }

    public Element getAsElement()
    {
        Element key = new Element(Element_Key);
        if (normalKey != null)
            key.setAttribute(Attr_Normal, normalKey);
        if (shiftKey != null)
            key.setAttribute(Attr_Shift, shiftKey);
        if (altKey != null)
            key.setAttribute(Attr_Alt, altKey);
        if (altshiftKey != null)
            key.setAttribute(Attr_AltGr, altshiftKey);
        return key;
    }
View Full Code Here

    public static void main(String[] args)
    {
        for (KeyboardLayout layout : getInstance().values())
            try
            {
                Element root = layout.getAsElement();
                File file = new File(layout.name + ".xml");
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                Format format = Format.getPrettyFormat();
                format.setEncoding("utf-16");
                format.setTextMode(Format.TextMode.TRIM);
View Full Code Here

    this.annotatorNames = annotatorNames;
  }

  public Collection<KnowtatorAnnotation> parse(URI knowtatorXML) throws JDOMException, IOException {

    Element annotationsElem = new SAXBuilder().build(knowtatorXML.toURL()).getRootElement();

    // parse <annotation> elements
    Set<String> ignoredAnnotators = new HashSet<String>();
    Map<String, KnowtatorAnnotation> annotations = new HashMap<String, KnowtatorAnnotation>();
    for (Element annotationElem : annotationsElem.getChildren("annotation")) {
      for (Element annotatorElem : this.getChild(annotationElem, "annotator")) {
        String annotatorName = annotatorElem.getText();
        if (!this.annotatorNames.contains(annotatorName)) {
          ignoredAnnotators.add(annotatorName);
        } else {
          for (Element mentionElem : this.getChild(annotationElem, "mention")) {
            for (String id : this.getAttributeValue(mentionElem, "id")) {
              KnowtatorAnnotation annotation = new KnowtatorAnnotation();
              annotation.id = id;
              annotations.put(id, annotation);
              List<Element> spanElems = annotationElem.getChildren("span");
              if (!spanElems.isEmpty()) {
                for (Element spannedTextElem : this.getChild(annotationElem, "spannedText")) {
                  annotation.spannedText = spannedTextElem.getText();
                }
                for (Element spanElem : spanElems) {
                  for (String startStr : this.getAttributeValue(spanElem, "start")) {
                    for (String endStr : this.getAttributeValue(spanElem, "end")) {
                      annotation.addSpan(Integer.parseInt(startStr), Integer.parseInt(endStr));
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    LOGGER.fine(String.format("Ignored annotators %s in %s", ignoredAnnotators, knowtatorXML));

    // parse <stringSlotMention> elements
    Map<String, Slot<String>> stringSlots = new HashMap<String, Slot<String>>();
    for (Element slotMentionElem : annotationsElem.getChildren("stringSlotMention")) {
      for (IdAndSlot<String> idAndSlot : this.parseSlotMention(
          slotMentionElem,
          "stringSlotMentionValue")) {
        stringSlots.put(idAndSlot.id, idAndSlot.slot);
      }
    }

    // parse <booleanSlotMention> elements
    Map<String, Slot<Boolean>> booleanSlots = new HashMap<String, Slot<Boolean>>();
    for (Element slotMentionElem : annotationsElem.getChildren("booleanSlotMention")) {
      for (IdAndSlot<String> idAndSlot : this.parseSlotMention(
          slotMentionElem,
          "booleanSlotMentionValue")) {
        Slot<String> slot = idAndSlot.slot;
        Boolean value = Boolean.parseBoolean(slot.value);
        booleanSlots.put(idAndSlot.id, new Slot<Boolean>(slot.name, value));
      }
    }

    // parse <complexSlotMention> elements
    Map<String, Slot<KnowtatorAnnotation>> mentionSlots = new HashMap<String, Slot<KnowtatorAnnotation>>();
    for (Element slotMentionElem : annotationsElem.getChildren("complexSlotMention")) {
      for (IdAndSlot<String> idAndSlot : this.parseSlotMention(
          slotMentionElem,
          "complexSlotMentionValue")) {
        Slot<String> slot = idAndSlot.slot;
        KnowtatorAnnotation mention = annotations.get(slot.value);
        if (mention != null) {
          mentionSlots.put(idAndSlot.id, new Slot<KnowtatorAnnotation>(slot.name, mention));
        }
      }
    }

    // parse <classMention> elements
    for (Element classMentionElem : annotationsElem.getChildren("classMention")) {
      for (String id : this.getAttributeValue(classMentionElem, "id")) {
        KnowtatorAnnotation annotation = annotations.get(id);
        if (annotation == null) {
          continue;
        }
View Full Code Here

    return annotations.values();
  }

  private Option<Element> getChild(final Element element, final String cname) {
    final Element child = element.getChild(cname);
    if (child == null) {
      String xml = this.xmlOutputter.outputString(element);
      LOGGER.warning(String.format("no %s for %s", cname, xml));
    }
    return new Option<Element>(child);
View Full Code Here

     */
    private Element getContentNode(Document xml)
    {
      //Search for mw-content-text
    //Gloss starts inside the first <p> nodes and ends with the apparition of another node type (like <div> or <h2>)
    Element root=xml.getRootElement();
    Element body=null;
    for(Element e:root.getChildren())
    {
      if(e.getName().equals("body"))
      {
        body=e;
        break;
      }
    }
    Element content=null;
    for(Element e:body.getChildren())
    {
      if(e.getAttribute("id")!=null&&e.getAttributeValue("id").equals("content"))
      {
        content=e;
        break;
      }
    }
    Element bodycontent=null;
    for(Element e:content.getChildren())
    {
      if(e.getAttribute("id")!=null&&e.getAttribute("id").getValue().equals("bodyContent"))
      {
        bodycontent=e;
        break;
      }
    }
    Element gloss=null;
    for(Element e:bodycontent.getChildren())
    {
      if(e.getAttribute("id")!=null&&e.getAttribute("id").getValue().equals("mw-content-text"))
      {
        gloss=e;
View Full Code Here

          Filter<? extends Content> or=f.or(new ElementFilter("span"));
          for(Content c:div.getDescendants(or))
          {
            if(c.getCType()==CType.Element)
            {
              Element word=(Element)c;
              if(word.getName().equals("a"))
              {
                String href=word.getAttributeValue("href");
                if(href!=null&&href.startsWith("/wiki"))
                {
                  urls.add(new URL(this.path+href));
                  hindex.add(new Integer(heads.size()-1));
                }
              }
              else
              {
                if(word.getAttributeValue("class")!=null && word.getAttributeValue("class").equals("mw-headline"))
                {
                  heads.add(word.getAttributeValue("id"));
                  Element e=word.getParentElement();
                  levels.add(new Integer(Integer.parseInt(e.getName().substring(1))-2));               
                }
              }
            }
          }
          break;
        }
      }
      ArrayList<Sense> senses=new ArrayList<Sense>(urls.size());
      for(int i=0;i<urls.size();i++)
      {
        String urlx=urls.get(i).getFile().replace("/wiki/", "");
        if(!this.isNotAnArticle(urlx))//it is a sense
        {                   
          senses.add(this.getSense(urlx.replace("/", "")));
       
      }
      ArrayList<Count> counts=new ArrayList<Count>();
      counts.add(this.getWikiCounts(lemma));      ;     
      l=new Lemma(lemma,"",senses,counts,this.name);
    }
    else
    {
      url=new URL(this.path+"wiki/"+lemma.replace(" ", "_"));
      xml=this.loadURL(url);
      if(xml!=null)
        text=xml.getRootElement().getValue();
      if(xml!=null&&!text.contains(this.missingMSG)&&!text.contains(this.wikiErrorMSG))
      {
        if(text.contains(this.disambiguationMSG)&&!this.jump)
        {         
          this.jump=true;
          ArrayList<Sense> senses=new ArrayList<Sense>();
          Element body=this.getContentNode(xml);
          for(Element e:body.getChildren())
          {
           
            if(e.getAttributeValue("class")!=null&&e.getAttributeValue("class").equals("dablink"))
            {
              for(Content c:e.getContent())
              {
                if(c.getCType().equals(CType.Element))
                {
                  Element a=((Element)c);
                  if(a.getName().equals("a"))
                  {
                    String sid=a.getAttributeValue("href");
                    sid=sid.substring(sid.indexOf("wiki/")+5);
                    sid=sid.replace(this.disambiguationWord, "");
                    Lemma ll=this.getLemma(sid);
                    if(ll!=null)
                    {
View Full Code Here

TOP

Related Classes of Question17_10.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.