Java String Replace replaceUnsafeNamespaceDelimiters(String input)

Here you can find the source of replaceUnsafeNamespaceDelimiters(String input)

Description

* Replaces non-alphanumeric namespace delimiters in input with an alphanumeric form that can be handled by Vampire and other provers.

License

Apache License

Parameter

Parameter Description
input The String representation of a SUO-KIF Formula or other expression

Return

String The input string with unsafe namespace delimiters replaced by a safe alphanumeric form

Declaration

public static String replaceUnsafeNamespaceDelimiters(String input) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

import java.util.List;

public class Main {
    /** *************************************************************
     * A String token that separates a qualified KIF term name
     * from the namespace abbreviation prefix that qualifies it.
     *///from  w  w  w  .jav a  2 s.  c  o m
    private static String KIF_NAMESPACE_DELIMITER = ":";
    /** *************************************************************
     * A String token that separates a qualified term name from
     * the W3C namespace abbreviation prefix that qualifies it.
     */
    private static String W3C_NAMESPACE_DELIMITER = ":";
    /** ***************************************************************
     * A "safe" alphanumeric ASCII string that can be substituted for
     * the W3C or SUO-KIF string delimiting a namespace prefix from an
     * unqualified term name.  The safe delimiter is used to produce
     * input formulae or files that can be loaded by Vampire and other
     * provers unable to handle term names containing non-alphanumeric
     * characters.
     */
    private static String SAFE_NAMESPACE_DELIMITER = "0xx1";

    /** ***************************************************************
     * Replaces non-alphanumeric namespace delimiters in input with an
     * alphanumeric form that can be handled by Vampire and other
     * provers.
     *
     * @param input The String representation of a SUO-KIF Formula or
     * other expression
     *
     * @return String The input string with unsafe namespace
     * delimiters replaced by a safe alphanumeric form
     */
    public static String replaceUnsafeNamespaceDelimiters(String input) {

        String output = input;
        try {
            if (isNonEmptyString(output)) {
                String safe = ("$1" + getSafeNamespaceDelimiter() + "$2");
                List<String> unsafe = Arrays.asList(getKifNamespaceDelimiter(), getW3cNamespaceDelimiter());
                for (String delim : unsafe) {
                    output = output.replaceAll("(\\w)" + delim + "(\\w)", safe);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return output;
    }

    /** ***************************************************************
     * @param obj Any object
     * @return true if obj is a non-empty String, else false.
     */
    public static boolean isNonEmptyString(Object obj) {

        return ((obj instanceof String) && !obj.equals(""));
    }

    /** ***************************************************************
     * Returns a "safe" alphanumeric ASCII string that can be
     * substituted for the W3C or SUO-KIF string delimiting a
     * namespace prefix from an unqualified term name.  The safe
     * delimiter is used to produce input formulae or files that can
     * be loaded by Vampire and other provers unable to handle term
     * names containing non-alphanumeric characters.
     */
    public static String getSafeNamespaceDelimiter() {
        return SAFE_NAMESPACE_DELIMITER;
    }

    /** *************************************************************
     * Returns the string used in SUO-KIF to separate a namespace
     * prefix from the term it qualifies.
     */
    public static String getKifNamespaceDelimiter() {
        return KIF_NAMESPACE_DELIMITER;
    }

    /** ***************************************************************
     * Returns the string preferred by W3C to separate a namespace
     * prefix from the term it qualifies.
     */
    public static String getW3cNamespaceDelimiter() {
        return W3C_NAMESPACE_DELIMITER;
    }
}

Related

  1. replaceIgnoreCase(String source, String strBeReplace, String strReplaced)
  2. replaceNonPrintableAsciiCharacters(String str)
  3. replaceOnce(String template, String placeholder, String replacement)
  4. replaceSign(String sourceStr, char startc, char endc, String replaceStr)
  5. replaceSpace(String str, int actualLength)
  6. replaceWildcards(String wildcardPattern)
  7. searchAndReplace(String source, String search, String replace)
  8. strReplaceOld(String strText, String strFrom, String strTo, boolean bMultiple)
  9. subStitute(String value, String pattern, String replacement)