Regular Expression for Words Starting with ‘Wh’ and Words Starting the Question

<?php

if(isset($_POST['submit'])) {
    $file = $_FILES['inputFile']['tmp_name']; //take file input
    $filename = $_FILES['inputFile']['name']; //get filename
    list($filename,$fileExt) = explode('.',$filename); //get file extension
    if($fileExt == 'txt') { //allow only txt files
        $fileContent = file_get_contents($file); //get all the contents of the file as a string

        foreach(preg_split('/[\s?.!,;]/',$fileContent) as $word) {  //split string to words
                if(preg_match('/\bwh\w*\b/i',$word)) { //check the word starting with 'wh'
                    $wordWithWh[$word] = $wordWithWh[$word] + 1; //store as an array with the count of each word.
                }
        }

        $sentence = preg_split('/([?.!])/',$fileContent,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); //split the sentence with .!
        $question = array();
        for($i = 0; $i<count($sentence);$i++) {
            if($sentence[$i + 1] == '?') {  //check if the sentence is a question
                array_push($question,$sentence[$i]); //store the question sentence
            }
        }

        foreach($question as $statement) {
            $questionWord = preg_split('/[\s?.]/',$statement,-1,PREG_SPLIT_NO_EMPTY); //get the word starting the question
            $questionWithWord[$questionWord[0]] = $questionWithWord[$questionWord[0]] + 1; //store the word with the count
        }
    }else {
        echo 'Only Text File with extension .txt is allowed'; //error message if the file uploaded is not txt.
    }
}
?>

<form method="POST" name="regTest" enctype="multipart/form-data">
<input type="file" name="inputFile">
<input type="submit" name="submit" value="Submit">
</form>

<?php
if(!empty($wordWithWh)) {
echo 'Word Count Starts with wh' .'<br>';
foreach($wordWithWh as $key => $value) {
        echo $key .' :' . $value .'<br>';
}
}
if(!empty($questionWithWord)) {
echo '<br> Question Starts with <br>';
foreach($questionWithWord as $key => $value) {
    echo $key .' :' . $value . '<br>';
}
}
?>

Iterative Delta Debugging

Algorithm:

1
2
3
4
5
6
7
8
9
10
11
12
13
original_version = current_version = latest_version();
patchset = {}
original_result = current_result = test(original_version);
while (current_result = pass) {
current_version = predecessor(current_version);
current_result = test(current_version ⊕ patchset);
if (current_result = original_result) {
delta = DD(current_version, original_version);
patchset = patchset∪delta;
original_version = current_version;
}
}
return delta;

The ddmin algorithm proceeds by executing the following steps to find a 1-minimal test case:

1. Reduce to subset: Split the current configuration into n partitions. Test each partition for failure. If a partition does induce the failure, then treat it as the current configuration and resume at Step 1.
2. Reduce to complement: Test the complement of each partition. If any induces the failure then treat it as the current configuration and resume at Step 1.
3. Increase granularity: Try splitting the current configuration into smaller partitions, 2n if possible, where n is the current number of partitions. Resume at Step 1 with the smaller partitions. If the configuration cannot be broken down into smaller partitions, the current configuration is 1-minimal and the algorithm terminates.

How to Connect two Mobile Devices via Bluetooth in J2ME?

Bluetooth is a low-cost, short-range wireless technology that has become popular among those who want to create personal area networks (PANs). Java provides many APIs for the Bluetooth Connection. The core Java Bluetooth APIs, can be found in javax.bluetooth under JSR82. JSR 82 requires the Connected Limited Device Configuration (CLDC) as its lowest common denominator, and the Connected Device Configuration (CDC) is a superset of CLDC, so JABWT can be implemented on top of both CLDC- and CDC-based profiles.

There are basic procedure for establishing the connection via Bluetooth. These are listed below

    • The first step is the Device Discovery.
      • retrieveDevices() retrieves already discovered or known devices that are nearby.
      • startInquiry() initiates discovery of nearby devices, also called inquiry.
      • cancelInquiry() cancels any inquiry presently in progress.
      • deviceDiscovered() indicates whether a device has been discovered.
      • inquiryCompleted() indicates whether the inquiry has succeeded, triggered an error, or been canceled.

The DiscoveryAgent class supports discovery of both devices and services. DiscoveryAgent’s device discovery methods are used to initiate and cancel device discovery: The Bluetooth Discovery Agent invokes the DiscoveryListener’s device – discovery callback methods at different points in the inquiry phase: Device discovery begins with a call to startInquiry(). As the inquiry progresses, the Bluetooth Discovery Agent invokes the callback methods deviceDiscovered() and inquiryCompleted() as appropriate.

    • Once the device is discovered, then the two devices connect to each other.

For this purpose, one device will be the local device while the other Remote Device. The localdevice will provide a service of specified UUID and the remote device search for this specified UUID. Once the UUID is found, the two device accept and establish connection.

000webhost logo