📄 query2xml.java
字号:
/* * File: Query2Xml.java * Project: MPI Linguistic Application * Date: 02 May 2007 * * Copyright (C) 2001-2007 Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package mpi.search.content.query.xml;import mpi.search.content.query.model.AnchorConstraint;import mpi.search.content.query.model.Constraint;import mpi.search.content.query.model.ContentQuery;import mpi.search.content.query.model.DependentConstraint;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.util.Date;import java.util.List;/** * $Id: Query2Xml.java,v 1.3 2006/11/29 14:47:37 klasal Exp $ $Author: klasal $ */public class Query2Xml { /** Holds value of property DOCUMENT ME! */ private static final String ENCODING = "UTF-8"; /** * DOCUMENT ME! * * @param fileName DOCUMENT ME! * @param query DOCUMENT ME! * * @throws IOException DOCUMENT ME! */ public static void translate(String fileName, ContentQuery query) throws IOException { File outputFile = new File(fileName); OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream( outputFile), ENCODING); out.write("<?xml version=\"1.0\" encoding=\"" + ENCODING + "\"?>\n"); writeQueryToStream(query, out); out.close(); } /** * DOCUMENT ME! * * @param out DOCUMENT ME! * @param constraint DOCUMENT ME! * * @throws IOException DOCUMENT ME! */ public static void writeAttributes(OutputStreamWriter out, Constraint constraint) throws IOException { out.write("\" regularExpression=\""); out.write("" + constraint.isRegEx()); out.write("\" caseSensitive=\""); out.write("" + constraint.isCaseSensitive()); if (constraint.getLowerBoundary() != Long.MIN_VALUE) { out.write("\" from=\""); out.write("" + constraint.getLowerBoundary()); } if (constraint.getUpperBoundary() != Long.MAX_VALUE) { out.write("\" to=\""); out.write("" + constraint.getUpperBoundary()); } out.write("\" unit=\""); out.write(constraint.getUnit()); } /** * DOCUMENT ME! * * @param query * @param out * * @throws IOException */ public static void writeQueryToStream(ContentQuery query, OutputStreamWriter out) throws IOException { out.write("<query date=\"" + new Date(System.currentTimeMillis()).toString() + "\">\n"); out.write("<description>"); out.write(query.toString()); out.write("</description>\n"); List constraints = query.getConstraints(); AnchorConstraint anchorConstraint = (AnchorConstraint) constraints.get(0); if (anchorConstraint != null) { out.write("<anchorConstraint id=\""); out.write("" + anchorConstraint.getId()); writeAttributes(out, anchorConstraint); out.write("\">\n"); String[] tierNames = anchorConstraint.getTierNames(); for (int j = 0; j < tierNames.length; j++) { out.write("<tier>" + tierNames[j] + "</tier>"); } out.write("<pattern>" + anchorConstraint.getPattern() + "</pattern>\n"); out.write("</anchorConstraint>"); } for (int i = 1; i < constraints.size(); i++) { DependentConstraint dependentConstraint = (DependentConstraint) constraints.get(i); out.write("<dependentConstraint id=\""); out.write("" + dependentConstraint.getId()); out.write("\" mode=\""); out.write(dependentConstraint.getMode()); out.write("\" quantifier=\""); out.write(dependentConstraint.getQuantifier()); writeAttributes(out, dependentConstraint); out.write("\" id_ref=\""); out.write("" + ((Constraint) dependentConstraint.getParent()).getId()); out.write("\">\n"); out.write("<tier>" + dependentConstraint.getTierName() + "</tier>"); out.write("<pattern>" + dependentConstraint.getPattern() + "</pattern>\n"); out.write("</dependentConstraint>\n"); } out.write("</query>\n"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -