List of usage examples for org.jdom2 Element getChildText
public String getChildText(final String cname)
From source file:edu.byu.ece.rapidSmith.device.creation.PrimitiveDefsCorrector.java
License:Open Source License
private static void modifyPrimitiveElement(PrimitiveDef def, Element modificationEl) { PrimitiveElement element = def.getElement(modificationEl.getChildText("name")); if (element == null) assert false; Element typeEl = modificationEl.getChild("type"); if (typeEl != null) { element.setMux(false);//from w ww. ja v a 2 s . co m element.setBel(false); element.setConfiguration(false); element.setPin(false); switch (typeEl.getText()) { case "mux": element.setMux(true); break; case "bel": element.setBel(true); break; case "cfg": element.setConfiguration(true); break; case "pin": element.setPin(true); break; default: assert false; } } }
From source file:edu.byu.ece.rapidSmith.device.creation.PrimitiveDefsCorrector.java
License:Open Source License
private static void createPrimitiveElement(PrimitiveDef def, Element creationEl) { PrimitiveElement element = new PrimitiveElement(); def.addElement(element);//from w ww . ja v a 2 s . co m element.setName(creationEl.getChildText("name")); element.setMux(false); element.setBel(false); element.setConfiguration(false); element.setPin(false); switch (creationEl.getChildText("type")) { case "mux": element.setMux(true); break; case "bel": element.setBel(true); break; case "cfg": element.setConfiguration(true); break; case "pin": element.setPin(true); break; default: assert false; } }
From source file:edu.byu.ece.rapidSmith.device.creation.PrimitiveDefsCorrector.java
License:Open Source License
private static void modifyPinDirection(PrimitiveDef def, Element pinEl) { String elName = pinEl.getChildText("element"); String pinName = pinEl.getChildText("pin"); String dirName = pinEl.getChildText("direction"); PinDirection direction;/*w w w. j a v a 2 s . co m*/ switch (dirName) { case "in": direction = PinDirection.IN; break; case "out": direction = PinDirection.OUT; break; case "inout": direction = PinDirection.INOUT; break; default: throw new AssertionError("Invalid direction"); } PrimitiveElement element = def.getElement(elName); for (PrimitiveDefPin pin : element.getPins()) { if (pin.getInternalName().equals(pinName)) { pin.setDirection(direction); break; } } }
From source file:edu.byu.ece.rapidSmith.device.creation.PrimitiveDefsCorrector.java
License:Open Source License
private static Element getSiteTypeEl(Document deviceInfo, SiteType type) { Element siteTypesEl = deviceInfo.getRootElement().getChild("site_types"); for (Element siteTypeEl : siteTypesEl.getChildren("site_type")) { if (siteTypeEl.getChildText("name").equals(type.name())) return siteTypeEl; }/*from w w w .j ava2s. c om*/ throw new FileFormatException("no site type " + type.name() + " in familyInfo.xml"); }
From source file:edu.co.usbcali.ir.util.ExtractReutersNews.java
public void extractNewsFromXml(String path) { SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(path); String baseFileName = FilenameUtils.removeExtension(xmlFile.getName()); String lineSeparator = System.getProperty("line.separator"); try {//ww w . j a v a2 s . c o m Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List listReuters = rootNode.getChildren("REUTERS"); for (Object listElement : listReuters) { Element reuters = (Element) listElement; String newId = reuters.getAttributeValue("NEWID"); String date = reuters.getChildText("DATE"); List listText = reuters.getChildren("TEXT"); Element text = (Element) listText.get(0); String title = text.getChildText("TITLE"); String body = text.getChildText("BODY"); String reuterContent = title + lineSeparator + date + lineSeparator + lineSeparator + body; String reuterPath = "reuters/" + baseFileName + "-" + newId + ".txt"; WriteFile.writeFileContent(reuterContent, reuterPath); } } catch (JDOMException | IOException ex) { Logger.getLogger(ExtractReutersNews.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.ucla.loni.server.ServerUtils.java
License:Open Source License
/** * Parses a .pipe into a Pipefile//from w w w . j a v a2 s . co m */ public static Pipefile parseXML(Document doc) { try { Pipefile pipe = new Pipefile(); Element main = getMainElement(doc); String mainName = main.getName(); if (mainName.equals("dataModule")) { pipe.type = "Data"; } else if (mainName.equals("module")) { pipe.type = "Modules"; } else if (mainName.equals("moduleGroup")) { pipe.type = "Groups"; } else { throw new Exception("Pipefile has unknown type"); } // General Properties pipe.name = main.getAttributeValue("name", ""); pipe.packageName = main.getAttributeValue("package", ""); pipe.description = main.getAttributeValue("description", ""); pipe.tags = getChildrenText(main, "tag", ","); // Get type specific properties if (pipe.type.equals("Data")) { Element values = main.getChild("values"); if (values != null) { pipe.values = getChildrenText(values, "value", "\n"); } Element output = main.getChild("output"); if (output != null) { Element format = output.getChild("format"); if (format != null) { pipe.formatType = format.getAttributeValue("type"); } } } if (pipe.type.equals("Modules")) { pipe.location = main.getAttributeValue("location", ""); } if (pipe.type.equals("Modules") || pipe.type.equals("Groups")) { pipe.uri = main.getChildText("uri"); } return pipe; } catch (Exception e) { return null; } }
From source file:edu.unc.lib.deposit.normalize.Proquest2N3BagJob.java
License:Apache License
private Resource populateAggregate(Model model, PID primaryPID, List<?> attachmentElements, File attachmentDir, File contentFile, String title) { Property labelP = dprop(model, label); Property fileLocation = dprop(model, stagingLocation); Property defaultWebObjectP = cdrprop(model, defaultWebObject); Property hasModelP = fprop(model, hasModel); // Create the primary resource as a bag Bag primaryBag = model.createBag(primaryPID.getURI()); model.add(primaryBag, hasModelP, model.createResource(CONTAINER.getURI().toString())); model.add(primaryBag, hasModelP, model.createResource(AGGREGATE_WORK.getURI().toString())); // Assign title to the main object as a label if (title.length() > 128) model.add(primaryBag, labelP, title.substring(0, 128)); else//from w ww . java2s. c o m model.add(primaryBag, labelP, title); // Create default web object child entry for the main document PID defaultObjectPID = new PID("uuid:" + UUID.randomUUID()); Resource defaultObjectResource = model.createResource(defaultObjectPID.getURI()); primaryBag.add(defaultObjectResource); // Store the main content on the child model.add(defaultObjectResource, labelP, contentFile.getName()); model.add(defaultObjectResource, fileLocation, getRelativePath(contentFile)); // Store reference to content as the default web object model.add(primaryBag, defaultWebObjectP, defaultObjectResource); // Add the attachments as supplemental files for (Object attachmentObj : attachmentElements) { Element attachEl = (Element) attachmentObj; String filename = attachEl.getChildText("DISS_file_name"); String description = attachEl.getChildText("DISS_file_descr"); // Make the child entry with a new uuid PID pid = new PID("uuid:" + UUID.randomUUID()); Resource child = model.createResource(pid.getURI()); primaryBag.add(child); // Use the description as a label if one was provided if (description != null && description.trim().length() > 0) model.add(child, labelP, description); else model.add(child, labelP, filename); // Link the file to the child entry model.add(child, fileLocation, getRelativePath(new File(attachmentDir, filename))); } return primaryBag; }
From source file:elh.eus.absa.CorpusReader.java
License:Open Source License
private void extractOpinionsAbsaSemEval2014(InputStream fileName) { SAXBuilder sax = new SAXBuilder(); XPathFactory xFactory = XPathFactory.instance(); try {//from w w w .jav a2 s . co m Document doc = sax.build(fileName); XPathExpression<Element> expr = xFactory.compile("//sentence", Filters.element()); List<Element> sentences = expr.evaluate(doc); Integer sId = 0; //sentence id Integer oId = 0; //opinion id for (Element sent : sentences) { sId++; StringBuilder sb = new StringBuilder(); String sentString = sent.getChildText("text"); sb = sb.append(sentString); Element aspectTerms = sent.getChild("aspectTerms"); if (aspectTerms != null) { List<Element> aspectTermList = aspectTerms.getChildren(); for (Element aspectElem : aspectTermList) { oId++; String trgt = aspectElem.getAttributeValue("target"); Integer offsetFrom = Integer.parseInt(aspectElem.getAttributeValue("from")); Integer offsetTo = Integer.parseInt(aspectElem.getAttributeValue("to")); String polarity = aspectElem.getAttributeValue("polarity"); //String cat = aspectElem.getAttributeValue("category"); //create and add opinion to the structure Opinion op = new Opinion("o" + oId, trgt, offsetFrom, offsetTo, polarity, null, "s" + sId); this.addOpinion(op); } //System.out.println(sb.toString()); } } } catch (JDOMException | IOException e) { e.printStackTrace(); } }
From source file:elh.eus.absa.CorpusReader.java
License:Open Source License
/** * Read semeval-absa 2015 shared task formatted corpus and extract opinions. * // w ww . j a v a 2s . c o m * @param InputStream fileName: corpus * @param boolean nullSentOps: whether null opinions should be created for sentence with no opinion * (only used for semeval-absa 2015 formatted corpora) * */ private void extractOpinionsAbsaSemEval2015(InputStream fileName, boolean nullSentenceOps) { SAXBuilder sax = new SAXBuilder(); XPathFactory xFactory = XPathFactory.instance(); try { Document doc = sax.build(fileName); XPathExpression<Element> expr = xFactory.compile("//sentence", Filters.element()); List<Element> sentences = expr.evaluate(doc); String rId = ""; String sId = ""; //sentence id Integer oId = 0; //opinion id for (Element sent : sentences) { sId = sent.getAttributeValue("id"); rId = sId.replaceAll(":[0-9]+$", ""); if (rId.equalsIgnoreCase(sId)) { rId = sId.replaceAll("#[0-9]+$", ""); } //store the sentence and the corresponding review addRevSent(rId, sId); StringBuilder sb = new StringBuilder(); String sentString = sent.getChildText("text"); //add sentence to the reader object this.addSentence(sId, sentString); sb = sb.append(sentString); Element opinions = sent.getChild("Opinions"); if (opinions != null) { List<Element> opinionList = opinions.getChildren(); //there is no opinions if (opinionList.isEmpty()) { //System.err.println("kkkkk"); //create sentence at list, even if it has no opinion elements sId = sent.getAttributeValue("id"); addRevSent(rId, sId); String sentStr = sent.getChildText("text"); //add sentence to the reader object this.addSentence(sId, sentStr); if (nullSentenceOps) { oId++; //create and add opinion to the structure Opinion op = new Opinion("o" + oId, "NULL", 0, 0, "NULL", "NULL", sId); this.addOpinion(op); } } for (Element opElem : opinionList) { oId++; String trgt = opElem.getAttributeValue("target"); Integer offsetFrom = 0; Integer offsetTo = 0; try { offsetFrom = Integer.parseInt(opElem.getAttributeValue("from")); offsetTo = Integer.parseInt(opElem.getAttributeValue("to")); } catch (NumberFormatException ne) { } String polarity = opElem.getAttributeValue("polarity"); String cat = opElem.getAttributeValue("category"); //create and add opinion to the structure Opinion op = new Opinion("o" + oId, trgt, offsetFrom, offsetTo, polarity, cat, sId); this.addOpinion(op); //debugging sb.append("\n\t> " + "o" + oId + " " + trgt + " " + offsetFrom + "-" + offsetTo + " " + polarity + " " + cat); } //System.out.println(sb.toString()); } else { //System.err.println("kkkkk"); //create sentence at list, even if it has no opinion elements sId = sent.getAttributeValue("id"); addRevSent(rId, sId); String sentStr = sent.getChildText("text"); //add sentence to the reader object this.addSentence(sId, sentStr); if (nullSentenceOps) { oId++; //create and add opinion to the structure Opinion op = new Opinion("o" + oId, "NULL", 0, 0, "NULL", "NULL", sId); this.addOpinion(op); } } } } catch (JDOMException | IOException e) { e.printStackTrace(); } }
From source file:elh.eus.absa.CorpusReader.java
License:Open Source License
/** * Extract sentence texts from tabulated format. The function assumes the text is PoS tagged in * Conll tabulated format.//from ww w.ja v a 2 s. c o m * * @param fileName string: input corpus file path */ private void extractOpinionsTabText(InputStream fileName) { SAXBuilder sax = new SAXBuilder(); XPathFactory xFactory = XPathFactory.instance(); try { Document doc = sax.build(fileName); XPathExpression<Element> expr = xFactory.compile("//sentence", Filters.element()); List<Element> sentences = expr.evaluate(doc); String rId = ""; String sId = ""; //sentence id Integer oId = 0; //opinion id for (Element sent : sentences) { sId = sent.getAttributeValue("id"); rId = sId; oId++; /*store the sentence and the corresponding review * (in this case this info is redundant, because a whole review is represented by a sentence) */ addRevSent(rId, sId); //StringBuilder sb = new StringBuilder(); String sentString = sent.getChildText("text"); //add sentence to the reader object this.addSentence(sId, sentString); String polarity = sent.getAttributeValue("polarity"); if (polarity == null) { System.err.println("no polarity annotation for review " + rId + "." + " Review won't be taken into account"); continue; } String trgt = ""; String cat = "global"; Integer offsetFrom = 0; Integer offsetTo = 0; //create and add opinion to the structure Opinion op = new Opinion("o" + oId, trgt, offsetFrom, offsetTo, polarity, cat, sId); this.addOpinion(op); //debugging //sb.append("\n\t> "+"o"+oId+" "+trgt+" "+offsetFrom+"-"+offsetTo+" "+polarity+" "+cat); } //System.out.println(sentString); } catch (JDOMException | IOException e) { e.printStackTrace(); } }